Skip to content

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

Closed

Conversation

mbasmanova
Copy link
Contributor

Summary: velox::Expected<T> can be used by no-throw APIs to return result or error.

Differential Revision: D57496990

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 17, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57496990

Copy link

netlify bot commented May 17, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit d26063f
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/664798b699c6d5000874e067

@mbasmanova mbasmanova requested review from pedroerp and Yuhta May 17, 2024 16:45
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 17, 2024
Summary:

`velox::Expected<T>` can be used by no-throw APIs to return result or error.

Differential Revision: D57496990
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57496990

Copy link
Contributor

@xiaoxmeng xiaoxmeng left a 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>
Copy link
Contributor

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?

Copy link
Contributor Author

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"));
Copy link
Contributor

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)

Copy link
Contributor

@Yuhta Yuhta May 17, 2024

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"));
Copy link
Contributor

@pedroerp pedroerp May 17, 2024

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.

mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 17, 2024
Summary:

`velox::Expected<T>` can be used by no-throw APIs to return result or error.

Reviewed By: xiaoxmeng, Yuhta, pedroerp

Differential Revision: D57496990
@facebook-github-bot
Copy link
Contributor

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
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57496990

mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 20, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 20, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 21, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 22, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 22, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 22, 2024
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
mbasmanova added a commit to mbasmanova/velox-1 that referenced this pull request May 22, 2024
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
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in fbb3578.

Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
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
Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
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
facebook-github-bot pushed a commit that referenced this pull request Sep 20, 2024
Summary:
We have recently introduced velox::Expected (#9858) to use in non-void no-throw APIs. It's more proper to return that.

Pull Request resolved: #10997

Reviewed By: xiaoxmeng

Differential Revision: D63035456

Pulled By: Yuhta

fbshipit-source-id: 6c8322593f9677e1dfa70f719b2922429f418d57
facebook-github-bot pushed a commit that referenced this pull request Oct 14, 2024
Summary:
We have recently introduced velox::Expected (#9858) to use in non-void no-throw APIs. It's more proper to return that.

Pull Request resolved: #11246

Reviewed By: bikramSingh91

Differential Revision: D64335564

Pulled By: kgpai

fbshipit-source-id: 92be9d34c739577ece1c1b0a0df497045348692a
athmaja-n pushed a commit to athmaja-n/velox that referenced this pull request Jan 10, 2025
…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
athmaja-n pushed a commit to athmaja-n/velox that referenced this pull request Jan 10, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants