Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve the code style by introducing macros #2629

Closed
wants to merge 10 commits into from

Conversation

AntiTopQuark
Copy link
Contributor

Relate Issue: #2521

Introduced two macros for handling error codes: RETURN_IF_ERROR and RETURN_IF_ERR_FROM_ROCKSDB.

I haven't modified all the code yet, so could the project committer please review this code first to see if it’s acceptable?
If approved, I'll go through and update the other files as well.

@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 30, 2024

GET_OR_RET is already a generalized macro for both Status and StatusOr<T>.

You can refer to my comment #2521 (comment).

Comment on lines 387 to 397
#define RETURN_IF_ERR_FROM_ROCKSDB(expr, error_code, format_str, with_status_string) \
({ \
auto&& status = (expr); \
if (!status.ok()) { \
if (with_status_string) { \
return {error_code, fmt::format(format_str, status.ToString())}; \
} else { \
return {error_code, fmt::format(format_str)}; \
} \
} \
})
Copy link
Member

@PragmaTwice PragmaTwice Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several points:

  • Many code of this macro can be implemented by a ctor Status(rocksdb::Status&&), we don't need write them in the macro;
  • After such ctor is impl, this macro is useless since it also can be handled by GET_OR_RET;
  • This macro doesn't explicit specify the output type, which can trigger some weird issues (the return type can actually be not a Status, but rocksdb::Status, or even pair<int, string>).

Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

@PragmaTwice
Copy link
Member

You can check #2630 about how to implement rocksdb::Status forwarding without introducing a new macro.

@@ -397,3 +397,16 @@ bool StatusIsOK(const T& v) {
if (!StatusIsOK(status)) return std::forward<decltype(status)>(status); \
std::forward<decltype(status)>(status); \
}))

// NOLINTNEXTLINE
#define RETURN_IF_ERROR(...) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I don't think you've got my point. As I've said, this macro is useless and can be replaced by GET_OR_RET. Actually it's function is a subset of GET_OR_RET.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I don't think you've got my point. As I've said, this macro is useless and can be replaced by GET_OR_RET. Actually it's function is a subset of GET_OR_RET.

Firstly, Thank you very much for reviewing my submitted PR and providing valuable feedback! I truly appreciate your input and am grateful for the time you’ve spent helping me improve the code.

This macro can indeed be replaced by GET_OR_RET.

})

// NOLINTNEXTLINE
#define RETURN_IF_ERR_FROM_ROCKSDB(s, code, msg) \
Copy link
Member

@PragmaTwice PragmaTwice Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I already said, we only need a function/method/ctor/operator T, instead of a macro. If we can complete some task via function/method, please never introduce a new macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I already said, we only need a function/method/ctor/operator T, instead of a macro. If we can complete some task via function/method, please never introduce a new macro.

Regarding the comment, after careful consideration, I realize that I may not have fully grasped your intention. Specifically, I feel that without introducing a new macro, it becomes challenging to directly return a new Status object.

@AntiTopQuark
Copy link
Contributor Author

I apologize, but upon reflection, I believe this PR offers minimal value. Additionally, due to my current busy schedule and limited energy, I am unable to continue this work. I apologize once again.

cc @PragmaTwice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants