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

Differentiate successful and failed callback #155

Closed
MaksymZavershynskyi opened this issue May 18, 2020 · 6 comments · Fixed by #554
Closed

Differentiate successful and failed callback #155

MaksymZavershynskyi opened this issue May 18, 2020 · 6 comments · Fixed by #554
Assignees

Comments

@MaksymZavershynskyi
Copy link
Contributor

We need for a function to differentiate result of a successful and failed callback. Currently, when we declare function that expects a callback like this:

pub fn callback_receiver(&self, #[callback] arg0: A, arg1: B, #[callback] arg2: C) {
}

It will fail if execution of whatever produced arg0 or arg2 failed. Instead it should be:

pub fn callback_receiver(&self, #[callback_result] arg0: Result<A>, arg1: B, #[callback_result] arg2: Result<C>) {
// Code that handles cases of arg0 and arg2 errors.
}
@evgenykuzyakov
Copy link
Contributor

#138

@mikedotexe
Copy link
Contributor

Want to note that this has become important to two partners looking to build on NEAR.

@evgenykuzyakov
Copy link
Contributor

evgenykuzyakov commented May 18, 2021

TODO:

  • Implement PromiseResult as a type, which is Result<T, PromiseError>
  • Implement PromiseError, for now there is 3 types Failed, Missing and NotReady, but NotReady is unreachable. Missing is when the number of input dependencies is less than the expected number of callback result arguments
  • Implement callback_result macro that expects PromiseResult<T>
  • Soft rename callback to callback_unwrap and mark callback as deprecated.

@austinabell
Copy link
Contributor

TODO:

  • Implement PromiseResult as a type, which is Result<T, PromiseError>
  • Implement PromiseError, for now there is 3 types Failed, Missing and NotReady, but NotReady is unreachable. Missing is when the number of input dependencies is less than the expected number of callback result arguments
  • Implement callback_result macro that expects PromiseResult<T>
  • Soft rename callback to callback_unwrap and mark callback as deprecated.

And any thoughts on what to do with callback_vec wrt this? Can just open a separate issue for this, but curious if anyone has thoughts

@matklad
Copy link
Contributor

matklad commented May 19, 2021

Missing is when the number of input dependencies is less than the expected number of callback result arguments

I wonder if this needs to be an error type, or a panic. Naively, it seems that the number of input promises is a static property of the contract, and, if you are missing a promise, this is a bug. Bugs in Rust are generally handled via a panic.

Are there cases where we might want to recover from a missing promise?

@austinabell austinabell self-assigned this Aug 26, 2021
@austinabell
Copy link
Contributor

austinabell commented Aug 26, 2021

TODO:

  • Implement PromiseResult as a type, which is Result<T, PromiseError>
  • Implement PromiseError, for now there is 3 types Failed, Missing and NotReady, but NotReady is unreachable. Missing is when the number of input dependencies is less than the expected number of callback result arguments
  • Implement callback_result macro that expects PromiseResult<T>
  • Soft rename callback to callback_unwrap and mark callback as deprecated.

Opting against having a PromiseResult type since one already existed and is used in env. It's just a convenience wrapper, so the type will be Result<T, PromiseError>, but can create a convenience type called CallbackResult or something but prob best to be careful adding more of these.

Also, currently confused on how Missing could ever be hit, but maybe it'll be more clear when implementing. (nevermind, it was just for vector results)

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

Successfully merging a pull request may close this issue.

5 participants