kvrocks icon indicating copy to clipboard operation
kvrocks copied to clipboard

Improve the code style by introducing macros

Open git-hulk opened this issue 1 year ago • 5 comments

Followup code improvements mentioned in PR #2508. Currently, we check and return error if the status is not ok in many many places, which can be improved by introducing macros.

The naming candidates can be:

  • RETURN_NOT_OK
  • RETURN_IF_ERROR

and for converting the rocksdb status if there is an error:

  • RETURN_NOT_OK_FROM_ROCKSDB
  • RETURN_IF_ERR_FROM_ROCKSDB

Originally posted by @mapleFU in https://github.com/apache/kvrocks/pull/2508#pullrequestreview-2276461263

git-hulk avatar Sep 04 '24 02:09 git-hulk

@AntiTopQuark Would you like to take this issue?

git-hulk avatar Sep 04 '24 02:09 git-hulk

@AntiTopQuark Would you like to take this issue?

I’d be happy to take on this issue. :)

AntiTopQuark avatar Sep 04 '24 13:09 AntiTopQuark

The first macro is duplicated with the current GET_OR_RET macro.

PragmaTwice avatar Sep 07 '24 07:09 PragmaTwice

For the second I think it depends on the context, e.g. rocksdb::Status -> Status? rocksdb::Status -> rocksdb::Status?

We can extend GET_OR_RET for the latter, and the former doesn't require new macro.

PragmaTwice avatar Sep 07 '24 07:09 PragmaTwice

For the second I think it depends on the context, e.g. rocksdb::Status -> Status? rocksdb::Status -> rocksdb::Status?

We can extend GET_OR_RET for the latter, and the former doesn't require new macro.

Yes, my bad. GET_OR_RET allows ignoring the return value, so the former one is unnecessary.

git-hulk avatar Sep 07 '24 12:09 git-hulk