Skip to content

Commit 7def0a5

Browse files
authored
chore: add JSON ABI error entry to FuelError.metadata (#3921)
1 parent 4e018a5 commit 7def0a5

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

.changeset/cyan-pandas-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fuel-ts/account": patch
3+
---
4+
5+
chore: add JSON ABI error entry to `FuelError.metadata`

packages/account/src/providers/utils/extract-tx-error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function buildAbiErrorMessage(
138138

139139
return new FuelError(ErrorCode.SCRIPT_REVERTED, errorMessage, {
140140
...metadata,
141+
abiError,
141142
reason,
142143
});
143144
}

packages/fuel-gauge/src/revert-error.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ describe('Revert Error Testing', () => {
386386
} = launched;
387387

388388
const script = new ScriptError(adminWallet);
389-
const errorCode = Object.values(ScriptError.abi.errorCodes)[0];
389+
const abiError = Object.values(ScriptError.abi.errorCodes)[0];
390390

391391
await expectToThrowFuelError(
392392
async () => {
@@ -395,14 +395,15 @@ describe('Revert Error Testing', () => {
395395
},
396396
new FuelError(
397397
ErrorCode.SCRIPT_REVERTED,
398-
`A sway "panic" expression was invoked with the message: "a str panic".\n\nThis error originated at ${JSON.stringify(errorCode.pos, null, 2)}`,
398+
`A sway "panic" expression was invoked with the message: "a str panic".\n\nThis error originated at ${JSON.stringify(abiError.pos, null, 2)}`,
399399
{
400400
logs: [],
401401
groupedLogs: {},
402402
receipts: expect.any(Array<TransactionResultReceipt>),
403403
panic: false,
404404
revert: true,
405405
reason: '18446744069414584320',
406+
abiError,
406407
}
407408
)
408409
);
@@ -416,7 +417,7 @@ describe('Revert Error Testing', () => {
416417
} = launched;
417418

418419
const script = new ScriptError(adminWallet);
419-
const errorCode = Object.values(ScriptError.abi.errorCodes)[1];
420+
const abiError = Object.values(ScriptError.abi.errorCodes)[1];
420421

421422
await expectToThrowFuelError(
422423
async () => {
@@ -425,7 +426,7 @@ describe('Revert Error Testing', () => {
425426
},
426427
new FuelError(
427428
ErrorCode.SCRIPT_REVERTED,
428-
`A sway "panic" expression was invoked with the value: "A".\n\nThis error originated at ${JSON.stringify(errorCode.pos, null, 2)}`,
429+
`A sway "panic" expression was invoked with the value: "A".\n\nThis error originated at ${JSON.stringify(abiError.pos, null, 2)}`,
429430
{
430431
groupedLogs: {
431432
[ZeroBytes32]: ['A'],
@@ -435,6 +436,7 @@ describe('Revert Error Testing', () => {
435436
panic: false,
436437
revert: true,
437438
reason: '18446744069414584321',
439+
abiError,
438440
}
439441
)
440442
);
@@ -449,7 +451,7 @@ describe('Revert Error Testing', () => {
449451

450452
const script = new ScriptError(adminWallet);
451453

452-
const errorCode = Object.values(ScriptError.abi.errorCodes)[2];
454+
const abiError = Object.values(ScriptError.abi.errorCodes)[2];
453455

454456
const decodedValue = { B: [bn('0x400'), 42] };
455457

@@ -460,12 +462,13 @@ describe('Revert Error Testing', () => {
460462
},
461463
new FuelError(
462464
ErrorCode.SCRIPT_REVERTED,
463-
`A sway "panic" expression was invoked with the value: ${JSON.stringify(decodedValue)}.\n\nThis error originated at ${JSON.stringify(errorCode.pos, null, 2)}`,
465+
`A sway "panic" expression was invoked with the value: ${JSON.stringify(decodedValue)}.\n\nThis error originated at ${JSON.stringify(abiError.pos, null, 2)}`,
464466
{
465467
receipts: expect.any(Array<TransactionResultReceipt>),
466468
panic: false,
467469
revert: true,
468470
reason: '18446744069414584322',
471+
abiError,
469472
}
470473
)
471474
);
@@ -479,7 +482,7 @@ describe('Revert Error Testing', () => {
479482
} = launched;
480483

481484
const script = new ScriptError(adminWallet);
482-
const errorCode = Object.values(ScriptError.abi.errorCodes)[3];
485+
const abiError = Object.values(ScriptError.abi.errorCodes)[3];
483486

484487
const decodedValue = { B: [bn('0x0'), 16] };
485488

@@ -490,12 +493,13 @@ describe('Revert Error Testing', () => {
490493
},
491494
new FuelError(
492495
ErrorCode.SCRIPT_REVERTED,
493-
`A sway "panic" expression was invoked with the value: ${JSON.stringify(decodedValue)}.\n\nThis error originated at ${JSON.stringify(errorCode.pos, null, 2)}`,
496+
`A sway "panic" expression was invoked with the value: ${JSON.stringify(decodedValue)}.\n\nThis error originated at ${JSON.stringify(abiError.pos, null, 2)}`,
494497
{
495498
receipts: expect.any(Array<TransactionResultReceipt>),
496499
panic: false,
497500
revert: true,
498501
reason: '18446744069414584323',
502+
abiError,
499503
}
500504
)
501505
);

0 commit comments

Comments
 (0)