Skip to content

Returning error codes from init and receive functions #22

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

Merged
merged 22 commits into from
Mar 11, 2021
Merged

Conversation

amaurremi
Copy link
Contributor

Note: the changes in the auction smart contract are hard to see because I did a reformatting. But the only "real" changes are that the custom error types derive Reject (like in the other example contracts), and that it removes fields from the BidTooLow error, because we don't support enums with fields yet.

@abizjak
Copy link
Contributor

abizjak commented Mar 2, 2021

Note: the changes in the auction smart contract are hard to see because I did a reformatting. But the only "real" changes are that the custom error types derive Reject (like in the other example contracts), and that it removes fields from the BidTooLow error, because we don't support enums with fields yet.

Could you also add the auction contract to the CI here:

to avoid such issues in the future.

Copy link
Contributor

@abizjak abizjak left a comment

Choose a reason for hiding this comment

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

I think this is on the right track.

It needs some polish, but even in this form it will provide a much better experience on the chain than the "no information" we had before.

@amaurremi
Copy link
Contributor Author

It looks like we currently won't able to annotate enum fields with #[from = ErrorType] attributes (see rust-lang/rust#53012). I'm instead going to annotate the whole enum as #[derive(..., Reject(MyEnumField -> ParseError))] or something of the like.

@amaurremi
Copy link
Contributor Author

On a second look, derive macro helper attributes are a thing--wonderful.

Copy link
Contributor

@abizjak abizjak left a comment

Choose a reason for hiding this comment

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

See comments.

@amaurremi amaurremi marked this pull request as ready for review March 10, 2021 13:01
- Make it explicit that reject must be non-zero.
- Fix the Default of Reject instance to be non-zero.
- Remove the need for an allocator in generated code (format! uses an allocator)
This is to avoid confusion between the From instance and the error code that is
ultimately displayed to the user.

The remaining issue is that the variant tags are still positive since we cannot
easily modify them in a derive macro. We'd have to have another attribute macro
to achieve this automatically.
abizjak
abizjak previously approved these changes Mar 11, 2021
This brings in i/u128 changes as well.
@abizjak abizjak merged commit 83bf7c2 into main Mar 11, 2021
@abizjak abizjak deleted the mra/sc-errors branch March 11, 2021 08:09
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