Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grpc-graphql-error-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': minor
---

Expose execution error metadata in Core API transaction results for gRPC and GraphQL clients.
5 changes: 5 additions & 0 deletions packages/sui/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,14 @@ export namespace SuiClientTypes {
objectId: string;
}

export interface ExecutionErrorMetadata {
message?: string;
}

export type ExecutionError = {
message: string;
command?: number;
metadata?: ExecutionErrorMetadata;
} & EnumOutputShape<{
MoveAbort: MoveAbort;
SizeError: SizeError;
Expand Down
16 changes: 16 additions & 0 deletions packages/sui/src/graphql/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,9 @@ function parseGraphQLExecutionError(
executionError: GraphQLExecutionError | null | undefined,
): SuiClientTypes.ExecutionError {
const name = mapGraphQLExecutionErrorKind(executionError);
const metadata = parseGraphQLExecutionErrorMetadata(
(executionError as { metadata?: unknown } | null | undefined)?.metadata,
);

if (name === 'MoveAbort' && executionError?.abortCode != null) {
const location = parseGraphQLMoveLocation(executionError);
Expand Down Expand Up @@ -1002,6 +1005,7 @@ function parseGraphQLExecutionError(
: undefined,
}),
command,
metadata,
MoveAbort: {
abortCode: executionError.abortCode!,
location,
Expand All @@ -1013,10 +1017,22 @@ function parseGraphQLExecutionError(
return {
$kind: 'Unknown',
message: executionError?.message ?? 'Transaction failed',
metadata,
Unknown: null,
};
}

function parseGraphQLExecutionErrorMetadata(
metadata: unknown,
): SuiClientTypes.ExecutionError['metadata'] {
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
return undefined;
}

const message = (metadata as { message?: unknown }).message;
return typeof message === 'string' ? { message } : undefined;
}

function mapGraphQLExecutionErrorKind(
executionError: GraphQLExecutionError | null | undefined,
): string {
Expand Down
17 changes: 12 additions & 5 deletions packages/sui/src/graphql/generated/queries.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/sui/src/graphql/generated/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/sui/src/graphql/generated/tada-env.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/sui/src/graphql/queries/transactions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fragment TRANSACTION_FIELDS on Transaction {
status
executionError {
message
metadata
abortCode
identifier
constant
Expand Down Expand Up @@ -152,6 +153,7 @@ query resolveTransaction($transaction: JSON!, $doGasSelection: Boolean = true) {
status
executionError {
message
metadata
abortCode
identifier
constant
Expand Down
29 changes: 27 additions & 2 deletions packages/sui/src/grpc/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,13 @@ export class GrpcCoreClient extends CoreClient {
async getTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
options: SuiClientTypes.GetTransactionOptions<Include>,
): Promise<SuiClientTypes.TransactionResult<Include>> {
const paths = ['digest', 'transaction.digest', 'signatures', 'effects.status'];
const paths = [
'digest',
'transaction.digest',
'signatures',
'effects.status',
'effects.status.error.metadata',
];
if (options.include?.transaction) {
paths.push(
'transaction.sender',
Expand Down Expand Up @@ -346,7 +352,13 @@ export class GrpcCoreClient extends CoreClient {
async executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
options: SuiClientTypes.ExecuteTransactionOptions<Include>,
): Promise<SuiClientTypes.TransactionResult<Include>> {
const paths = ['digest', 'transaction.digest', 'signatures', 'effects.status'];
const paths = [
'digest',
'transaction.digest',
'signatures',
'effects.status',
'effects.status.error.metadata',
];
if (options.include?.transaction) {
paths.push(
'transaction.sender',
Expand Down Expand Up @@ -401,6 +413,7 @@ export class GrpcCoreClient extends CoreClient {
'transaction.transaction.digest',
'transaction.signatures',
'transaction.effects.status',
'transaction.effects.status.error.metadata',
];
if (options.include?.transaction) {
paths.push(
Expand Down Expand Up @@ -763,6 +776,7 @@ export class GrpcCoreClient extends CoreClient {
'transaction.transaction.expiration',
'transaction.transaction.kind',
'transaction.effects.status',
'transaction.effects.status.error.metadata',
],
},
});
Expand Down Expand Up @@ -869,6 +883,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
const message = error.description ?? 'Unknown error';
const command = error.command != null ? Number(error.command) : undefined;
const details = error.errorDetails;
const metadata = error.metadata;

switch (details?.oneofKind) {
case 'abort': {
Expand All @@ -893,6 +908,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
: undefined,
}),
command,
metadata,
MoveAbort: parseMoveAbort(abort),
};
}
Expand All @@ -902,6 +918,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'SizeError',
message,
command,
metadata,
SizeError: {
name: mapErrorName(error.kind),
size: Number(details.sizeError.size ?? 0n),
Expand All @@ -914,6 +931,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'CommandArgumentError',
message,
command,
metadata,
CommandArgumentError: {
argument: details.commandArgumentError.argument ?? 0,
name: mapErrorName(details.commandArgumentError.kind),
Expand All @@ -925,6 +943,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'TypeArgumentError',
message,
command,
metadata,
TypeArgumentError: {
typeArgument: details.typeArgumentError.typeArgument ?? 0,
name: mapErrorName(details.typeArgumentError.kind),
Expand All @@ -936,6 +955,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'PackageUpgradeError',
message,
command,
metadata,
PackageUpgradeError: {
name: mapErrorName(details.packageUpgradeError.kind),
packageId: details.packageUpgradeError.packageId,
Expand All @@ -948,6 +968,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'IndexError',
message,
command,
metadata,
IndexError: {
index: details.indexError.index,
subresult: details.indexError.subresult,
Expand All @@ -959,6 +980,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'CoinDenyListError',
message,
command,
metadata,
CoinDenyListError: {
name: mapErrorName(error.kind),
coinType: details.coinDenyListError.coinType!,
Expand All @@ -971,6 +993,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'CongestedObjects',
message,
command,
metadata,
CongestedObjects: {
name: mapErrorName(error.kind),
objects: details.congestedObjects.objects,
Expand All @@ -982,6 +1005,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'ObjectIdError',
message,
command,
metadata,
ObjectIdError: {
name: mapErrorName(error.kind),
objectId: details.objectId,
Expand All @@ -993,6 +1017,7 @@ function parseGrpcExecutionError(error: GrpcExecutionError): SuiClientTypes.Exec
$kind: 'Unknown',
message,
command,
metadata,
Unknown: null,
};
}
Expand Down
31 changes: 31 additions & 0 deletions packages/sui/src/grpc/proto/sui/rpc/v2/execution_status.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading