-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Introduce velox::Expected #9858
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
Conversation
This pull request was exported from Phabricator. Differential Revision: D57496990 |
✅ Deploy Preview for meta-velox canceled.
|
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Differential Revision: D57496990
c38878d
to
9daa666
Compare
This pull request was exported from Phabricator. Differential Revision: D57496990 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
@@ -489,6 +490,10 @@ inline Status genericToStatus(Status&& st) { | |||
} | |||
|
|||
} // namespace internal | |||
|
|||
template <typename T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment block here explaining how we intend this to be used with a few examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks.
@@ -128,5 +128,23 @@ TEST(StatusTest, macros) { | |||
ASSERT_TRUE(didThrow) << "VELOX_CHECK_OK did not throw"; | |||
} | |||
|
|||
Expected<int> modulo(int a, int b) { | |||
if (b == 0) { | |||
return folly::makeUnexpected(Status::UserError("division by zero")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only annoying part with folly::Expected is that it doesn't let you to simply:
return Status::UserError("division by zero");
like you can with arrow::Result. We could try to work around it, but it doesn't let you do it by default (I'm not exactly sure why)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good concern, otherwise the macros won't work with Expected
@@ -128,5 +128,23 @@ TEST(StatusTest, macros) { | |||
ASSERT_TRUE(didThrow) << "VELOX_CHECK_OK did not throw"; | |||
} | |||
|
|||
Expected<int> modulo(int a, int b) { | |||
if (b == 0) { | |||
return folly::makeUnexpected(Status::UserError("division by zero")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also provide macros like other project do, such as:
VELOX_CHECK(b == 0, "division by zero");
or since we already have VELOX_CHECK, maybe VELOX_RETURN_IF
?
Semantically, we would probably need a set of macros, that throw (the VELOX_CHECK ones we have), and ones that just return an status. It would be a pain, but we could potentially rename VELOX_CHECK to VELOX_THROW (to make it more explicitly that it actually throws), and have VELOX_CHECK (and variants) to just return an error status.
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, pedroerp Differential Revision: D57496990
9daa666
to
bbfa46a
Compare
This pull request was exported from Phabricator. Differential Revision: D57496990 |
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, pedroerp Differential Revision: D57496990
bbfa46a
to
d26063f
Compare
This pull request was exported from Phabricator. Differential Revision: D57496990 |
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
Summary: `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990
This pull request has been merged in fbb3578. |
Summary: Pull Request resolved: facebookincubator#9858 `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990 fbshipit-source-id: 9f820d293e9b990633183e8daee73f6b12c2cb5e
Summary: Pull Request resolved: facebookincubator#9858 `velox::Expected<T>` can be used by no-throw APIs to return result or error. Reviewed By: xiaoxmeng, Yuhta, Magoja, pedroerp Differential Revision: D57496990 fbshipit-source-id: 9f820d293e9b990633183e8daee73f6b12c2cb5e
…ator#10997) Summary: We have recently introduced velox::Expected (facebookincubator#9858) to use in non-void no-throw APIs. It's more proper to return that. Pull Request resolved: facebookincubator#10997 Reviewed By: xiaoxmeng Differential Revision: D63035456 Pulled By: Yuhta fbshipit-source-id: 6c8322593f9677e1dfa70f719b2922429f418d57
…cubator#11246) Summary: We have recently introduced velox::Expected (facebookincubator#9858) to use in non-void no-throw APIs. It's more proper to return that. Pull Request resolved: facebookincubator#11246 Reviewed By: bikramSingh91 Differential Revision: D64335564 Pulled By: kgpai fbshipit-source-id: 92be9d34c739577ece1c1b0a0df497045348692a
Summary:
velox::Expected<T>
can be used by no-throw APIs to return result or error.Differential Revision: D57496990