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

Return error when call was reverted #121

Merged
merged 4 commits into from
Apr 3, 2024
Merged

Return error when call was reverted #121

merged 4 commits into from
Apr 3, 2024

Conversation

pmikolajczyk41
Copy link
Member

No description provided.

Copy link
Collaborator

@deuszx deuszx left a comment

Choose a reason for hiding this comment

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

Can you include some example? What's the context for using it? Isn't it equivalent to calling a method that returns Result<T, Err> and asserting it's Err?

@pmikolajczyk41
Copy link
Member Author

@deuszx https://github.com/Cardinal-Cryptography/ink-exercises/blob/main/exercises/1-drink-test/tests/lib.rs#L61

it's not that straitghtforward - if your message returned Err(E), then the call method returns Err(<Ok(Err(E))>.encode()). And it's better to handle this here, in drink, then every time on the client side

self.call_internal::<_, Result<(), E>>(None, message, args, endowment)
.expect_err("Call should fail")
.decode_revert::<Result<(), E>>()
.expect("Call should be reverted")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we're loosing information - decode_revert returns None if the underlying error is different than CallReverted. So, if it's anything else - we will fail on this expect and not provide any context for the developer to fix it.

Maybe, instead of returning Option from decode_revert, we could return a Result and on the Err side include the original error?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@pmikolajczyk41 pmikolajczyk41 merged commit 95223ce into main Apr 3, 2024
2 checks passed
@pmikolajczyk41 pmikolajczyk41 deleted the return-error branch April 3, 2024 10:22
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