-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[graphql] Add support for clever error resolution in graphql (#17338)
## Description Adds support for clever errors to GraphQL. So now, if you have code like the following: ```move module p::m { #[error] const ENotFound: vector<u8> = b"Element was unable to be found in the vector" public fun abort() { assert!(false, ENotFound); // Can also be an `abort ENotFound` } } ``` This will result in a humand-readable output from graphql: ``` Error in 1st command 'ENotFound' from module '0x8fd7251015bfd1dc4283bb3d38dc95a2769f75d621c871a81bb9c191a2860aaf::m' in function 'abort' at source line 6 The element was unable to be found in the vector ``` ## Test plan Added tests for all supported constant types, along with tests to make sure that we properly handle package upgrades and resolving to the correct version of a package when resolving clever errors. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [X] GraphQL: Adds support for more understandable and ergonomic Move error codes in Move 2024. - [ ] CLI: - [ ] Rust SDK:
- Loading branch information
Showing
10 changed files
with
805 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
248 changes: 248 additions & 0 deletions
248
crates/sui-graphql-e2e-tests/tests/errors/clever_errors.exp
Large diffs are not rendered by default.
Oops, something went wrong.
233 changes: 233 additions & 0 deletions
233
crates/sui-graphql-e2e-tests/tests/errors/clever_errors.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --protocol-version 39 --addresses P0=0x0 P1=0x0 --accounts A --simulator | ||
|
||
//# publish --upgradeable --sender A | ||
module P0::m { | ||
#[error] | ||
const ImAU8: u8 = 0; | ||
|
||
#[error] | ||
const ImAU16: u16 = 1; | ||
|
||
#[error] | ||
const ImAU32: u32 = 2; | ||
|
||
#[error] | ||
const ImAU64: u64 = 3; | ||
|
||
#[error] | ||
const ImAU128: u128 = 4; | ||
|
||
#[error] | ||
const ImAU256: u256 = 5; | ||
|
||
#[error] | ||
const ImABool: bool = true; | ||
|
||
#[error] | ||
const ImAnAddress: address = @6; | ||
|
||
#[error] | ||
const ImAString: vector<u8> = b"This is a string"; | ||
|
||
#[error] | ||
const ImNotAString: vector<u64> = vector[1,2,3,4,5]; | ||
|
||
public fun callU8() { | ||
abort ImAU8 | ||
} | ||
|
||
public fun callU16() { | ||
abort ImAU16 | ||
} | ||
|
||
public fun callU32() { | ||
abort ImAU32 | ||
} | ||
|
||
public fun callU64() { | ||
abort ImAU64 | ||
} | ||
|
||
public fun callU128() { | ||
abort ImAU128 | ||
} | ||
|
||
public fun callU256() { | ||
abort ImAU256 | ||
} | ||
|
||
public fun callAddress() { | ||
abort ImAnAddress | ||
} | ||
|
||
public fun callString() { | ||
abort ImAString | ||
} | ||
|
||
public fun callU64vec() { | ||
abort ImNotAString | ||
} | ||
|
||
public fun normalAbort() { | ||
abort 0 | ||
} | ||
|
||
public fun assertLineNo() { | ||
assert!(false); | ||
} | ||
} | ||
|
||
//# run P0::m::callU8 | ||
|
||
//# run P0::m::callU16 | ||
|
||
//# run P0::m::callU32 | ||
|
||
//# run P0::m::callU64 | ||
|
||
//# run P0::m::callU128 | ||
|
||
//# run P0::m::callU256 | ||
|
||
//# run P0::m::callAddress | ||
|
||
//# run P0::m::callString | ||
|
||
//# run P0::m::callU64vec | ||
|
||
//# run P0::m::normalAbort | ||
|
||
//# run P0::m::assertLineNo | ||
|
||
//# create-checkpoint | ||
|
||
//# run-graphql | ||
{ | ||
transactionBlocks(last: 11) { | ||
nodes { | ||
effects { | ||
status | ||
errors | ||
} | ||
} | ||
} | ||
} | ||
|
||
//# upgrade --package P0 --upgrade-capability 1,1 --sender A | ||
// Upgrade the module with new error values but using the same constant names | ||
// (etc) to make sure we properly resolve the module location for clever | ||
// errors. | ||
module P0::m { | ||
#[error] | ||
const ImAU8: u8 = 7; | ||
|
||
#[error] | ||
const ImAU16: u16 = 8; | ||
|
||
#[error] | ||
const ImAU32: u32 = 9; | ||
|
||
#[error] | ||
const ImAU64: u64 = 10; | ||
|
||
#[error] | ||
const ImAU128: u128 = 11; | ||
|
||
#[error] | ||
const ImAU256: u256 = 12; | ||
|
||
#[error] | ||
const ImABool: bool = false; | ||
|
||
#[error] | ||
const ImAnAddress: address = @13; | ||
|
||
#[error] | ||
const ImAString: vector<u8> = b"This is a string in v2"; | ||
|
||
#[error] | ||
const ImNotAString: vector<u64> = vector[1,2,3,4,5,6]; | ||
|
||
public fun callU8() { | ||
abort ImAU8 | ||
} | ||
|
||
public fun callU16() { | ||
abort ImAU16 | ||
} | ||
|
||
public fun callU32() { | ||
abort ImAU32 | ||
} | ||
|
||
public fun callU64() { | ||
abort ImAU64 | ||
} | ||
|
||
public fun callU128() { | ||
abort ImAU128 | ||
} | ||
|
||
public fun callU256() { | ||
abort ImAU256 | ||
} | ||
|
||
public fun callAddress() { | ||
abort ImAnAddress | ||
} | ||
|
||
public fun callString() { | ||
abort ImAString | ||
} | ||
|
||
public fun callU64vec() { | ||
abort ImNotAString | ||
} | ||
|
||
public fun normalAbort() { | ||
abort 0 | ||
} | ||
|
||
public fun assertLineNo() { | ||
assert!(false); | ||
} | ||
} | ||
|
||
//# run P0::m::callU8 | ||
|
||
//# run P0::m::callU16 | ||
|
||
//# run P0::m::callU32 | ||
|
||
//# run P0::m::callU64 | ||
|
||
//# run P0::m::callU128 | ||
|
||
//# run P0::m::callU256 | ||
|
||
//# run P0::m::callAddress | ||
|
||
//# run P0::m::callString | ||
|
||
//# run P0::m::callU64vec | ||
|
||
//# run P0::m::normalAbort | ||
|
||
//# run P0::m::assertLineNo | ||
|
||
//# create-checkpoint | ||
|
||
//# run-graphql | ||
{ | ||
transactionBlocks(last: 9) { | ||
nodes { | ||
effects { | ||
status | ||
errors | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.