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

Make CallBuilder and CreateBuilder error handling optional #1602

Merged
merged 11 commits into from
Jan 20, 2023

Conversation

HCastano
Copy link
Contributor

@HCastano HCastano commented Jan 20, 2023

This is a follow-up related to this comment.

We're updating the default APIs to unwrap any errors from the Contracts pallet, and
adding some new APIs in case callers do want to handle the errors.

I've also made a drive-by change to rename the fire() method to invoke(). This keeps
things consistent since we're wrapping a few methods with invoke in the name anyways.

Decided to do this in a follow-up. It's gonna make it easier for people to spot the breaking change.
Plus, extra green squares 🧑‍🌾

The breaking changes have been noted in the CHANGELOG.

@HCastano HCastano requested a review from athei January 20, 2023 00:56
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2023

Codecov Report

Merging #1602 (22a924d) into master (e2715f7) will decrease coverage by 5.82%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1602      +/-   ##
==========================================
- Coverage   71.48%   65.66%   -5.82%     
==========================================
  Files         205      205              
  Lines        6299     6286      -13     
==========================================
- Hits         4503     4128     -375     
- Misses       1796     2158     +362     
Impacted Files Coverage Δ
crates/env/src/call/call_builder.rs 0.00% <ø> (ø)
crates/env/src/call/create_builder.rs 0.00% <ø> (ø)
.../codegen/src/generator/trait_def/call_forwarder.rs 100.00% <ø> (ø)
crates/ink/ir/src/ir/contract.rs 0.00% <0.00%> (-100.00%) ⬇️
crates/ink/ir/src/ir/ink_test.rs 0.00% <0.00%> (-87.50%) ⬇️
crates/ink/ir/src/ir/trait_def/mod.rs 0.00% <0.00%> (-81.82%) ⬇️
crates/ink/ir/src/ir/storage_item/mod.rs 0.00% <0.00%> (-75.00%) ⬇️
crates/ink/ir/src/ir/storage_item/config.rs 0.00% <0.00%> (-68.75%) ⬇️
crates/ink/ir/src/ir/blake2.rs 20.83% <0.00%> (-58.34%) ⬇️
crates/ink/ir/src/ir/trait_def/config.rs 7.14% <0.00%> (-57.15%) ⬇️
... and 19 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines -358 to +360
.fire()
.unwrap_or_else(|err| ::core::panic!("{}: {:?}", #panic_str, err))
.try_fire()
.unwrap_or_else(|env_err| ::core::panic!("{}: {:?}", #panic_str, env_err))
.unwrap_or_else(|lang_err| ::core::panic!("{}: {:?}", #panic_str, lang_err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just call fire?

Copy link
Collaborator

@ascjones ascjones Jan 20, 2023

Choose a reason for hiding this comment

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

It looks like the only difference would be that the panic string includes extra info:

let panic_str = format!(
            "encountered error while calling <{} as {}>::{}",
            forwarder_ident, trait_ident, message_ident,
        );

Not sure how useful that is though

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think it is useful. If we just fire the panic message will just point to the line within the call builder file. Without backtraces (which we don't have) it will be quite hard to find the line which paniced.

examples/delegator/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM, though we should consider whether/how to unify those errors in a subsequent change.

@ascjones ascjones merged commit a83c937 into master Jan 20, 2023
@ascjones ascjones deleted the hc-remove-env-error-from-builders branch January 20, 2023 14:32
HCastano added a commit that referenced this pull request Jan 23, 2023
* Make default behaviour of `fire()` to return "raw" return value

* Update delegate call codepath to give option to handle `EnvError`

* Update `CreateBuilder::instantiate()`'s default cleaner as well

* Add a breaking change note in the changelog

* Fix delegator example

* Drive-by: rename `fire()` method to `invoke()`

This keeps this more consistent since we're wrapping a few methods with
`invoke` in the name anyways.

* Fix ERC-1155 example

* Update `Multisig` example

* Fix ContractRef tests

* Revert "Drive-by: rename `fire()` method to `invoke()`"

This reverts commit 72add05.

Decided it's best to do this in a standalone PR.

* Use instantiate instead of `try_instantiate` in `delegator`

Co-authored-by: Andrew Jones <ascjones@gmail.com>
@HCastano HCastano mentioned this pull request Jan 24, 2023
@ascjones ascjones mentioned this pull request Feb 15, 2023
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.

4 participants