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

Add docs on clever errors #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add docs on clever errors #99

wants to merge 1 commit into from

Conversation

tzakian
Copy link
Contributor

@tzakian tzakian commented Oct 30, 2024

Adds docs on clever errors.

conditions and still get useful error messages.

```move
module 0x42::macro_exporter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For coherence, I would split it into two codeblocks and use module labels.

> change due to any changes in the source file (e.g., due to auto-formatting, adding a new module
> member, or adding a newline).

## Clever Abort Codes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a link to a matching page in the book/?

or an abort is raised. They are a source feature and compile to a `u64` abort code value that
contains the information needed to access the line number, constant name, and constant value given
the clever error code and the module that the clever error constant was declared in. Because of
this, post-processing is required to go from the `u64` abort code value to a human-readable error
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this, post-processing is required to go from the `u64` abort code value to a human-readable error
this compilation, post-processing is required to go from the `u64` abort code value to a human-readable error

Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to be less ambiguous.

contains the information needed to access the line number, constant name, and constant value given
the clever error code and the module that the clever error constant was declared in. Because of
this, post-processing is required to go from the `u64` abort code value to a human-readable error
message. This post-processing is automatically performed by the Sui GraphQL server, as well as the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message. This post-processing is automatically performed by the Sui GraphQL server, as well as the
message. The post-processing is automatically performed by the Sui GraphQL server, as well as the

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this just reads cleaner given the previous sentence.


## Assertions with no Abort Codes

Assertions, and `abort` statements without an abort code will automatically derive an abort code
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Assertions, and `abort` statements without an abort code will automatically derive an abort code
Assertions and `abort` statements without an abort code will automatically derive an abort code

In hex, if `double_except_three(3)` is called, it will abort with a `u64` abort code as follows:

```
0x8000_7000_1000_0000
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
0x8000_7000_1000_0000
0x8000_0007_0001_0000

Is this correct? I was surprised that the value was set into the higher bits there.

In hex, if `assert_false(3)` is called, it will abort with a `u64` abort code as follows:

```
0x8000_4000_ffff_ffff
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's double check this with the one above


// Print the constant name (if any)
if identifier_index != 0xffff {
let constant_name = get_identifier_at_table_index(module, identifier_index);
Copy link
Contributor

Choose a reason for hiding this comment

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

get_identifier_at_table_index

I appreciate this is pseudo code, but do we have a method for this?

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.

3 participants