Skip to content

feat: implement support for new ABI error codes #3894

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 33 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
907a098
wip
Torres-ssf May 27, 2025
f8fb50f
re-add all forc projects to forc.toml file
Torres-ssf Jun 3, 2025
0bbe347
use forc 0.68.6
Torres-ssf Jun 3, 2025
a2c3df8
add errorCodes to both JsonAbi interfaces
Torres-ssf Jun 3, 2025
92ba410
add more errors to the script error
Torres-ssf Jun 3, 2025
b6ee1da
Merge branch 'master' into st/feat/abi-errors
Torres-ssf Jun 3, 2025
de3479a
using forc 0.68.7
Torres-ssf Jun 6, 2025
b2e6137
add new signal error
Torres-ssf Jun 6, 2025
393ceaa
adjust forc version to 0.68.7
Torres-ssf Jun 6, 2025
baaead7
lint forc file
Torres-ssf Jun 7, 2025
2bb037e
add more errors to script error program
Torres-ssf Jun 7, 2025
ace2232
add property abis to IExtractTxError interface
Torres-ssf Jun 7, 2025
49645b3
implement helper
Torres-ssf Jun 7, 2025
525b2ad
implement helper assembleSignalErrorMessage
Torres-ssf Jun 7, 2025
892fe62
implement helper assembleRevertError
Torres-ssf Jun 7, 2025
c77a07d
using property abis when calling extractTxErrorHelper
Torres-ssf Jun 7, 2025
4076ec2
add test cases for TX revert with new Sway errors
Torres-ssf Jun 7, 2025
6061ee8
add experimental flag to forc format
Torres-ssf Jun 7, 2025
aa87651
add experimental flag to forc forcBuildFlags
Torres-ssf Jun 7, 2025
49337a3
update forc version on internal apps
Torres-ssf Jun 7, 2025
2caf104
adjusting types names
Torres-ssf Jun 7, 2025
09aea67
fix import
Torres-ssf Jun 7, 2025
b5a16ab
fix import
Torres-ssf Jun 7, 2025
e0bb649
remove testing JSON ABI
Torres-ssf Jun 7, 2025
c818a18
remove unnecessary file
Torres-ssf Jun 7, 2025
8e4484a
get error codes at transpiler
Torres-ssf Jun 7, 2025
8a5390a
adjusting types for error pos property
Torres-ssf Jun 7, 2025
8cb2ea7
add changeset
Torres-ssf Jun 7, 2025
6808a00
update forc fmt command for forc-check script
Torres-ssf Jun 7, 2025
e29d2de
delete empty file
Torres-ssf Jun 10, 2025
24f10f9
code refact
Torres-ssf Jun 10, 2025
6b3623b
adjusting helper params to avoid breaking change
Torres-ssf Jun 10, 2025
4155d0b
lint
Torres-ssf Jun 10, 2025
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
11 changes: 11 additions & 0 deletions .changeset/hot-results-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@fuel-ts/transactions": patch
"@fuel-ts/abi-typegen": patch
"@fuel-ts/abi-coder": patch
"@fuel-ts/versions": patch
"@fuel-ts/account": patch
"@fuel-ts/program": patch
"@internal/forc": patch
---

feat: implement support for new ABI error codes
2 changes: 1 addition & 1 deletion apps/create-fuels-counter-guide/fuel-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
channel = "testnet"

[components]
forc = "0.68.6"
forc = "0.68.7"
fuel-core = "0.43.1"
2 changes: 1 addition & 1 deletion internal/forc/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.68.6
0.68.7
2 changes: 1 addition & 1 deletion packages/abi-coder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { Coder, InputValue, DecodedValue } from './encoding/coders/AbstractCoder
export type { FunctionFragment } from './FunctionFragment';
export * from './encoding/coders';
export { Interface } from './Interface';
export type { JsonAbi } from './types/JsonAbiNew';
export type { JsonAbi, ErrorCode as JsonAbiErrorCode } from './types/JsonAbiNew';
export {
SCRIPT_FIXED_SIZE,
INPUT_COIN_FIXED_SIZE,
Expand Down
14 changes: 14 additions & 0 deletions packages/abi-coder/src/types/JsonAbiNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface JsonAbi {
readonly loggedTypes: readonly LoggedType[];
readonly messagesTypes: readonly MessageType[];
readonly configurables: readonly Configurable[];
readonly errorCodes?: Record<string, ErrorCode>;
}

export interface ConcreteType {
Expand Down Expand Up @@ -99,3 +100,16 @@ export interface Configurable {
readonly concreteTypeId: string;
readonly offset: number;
}

export interface ErrorPosition {
pkg: string;
file: string;
line: number;
column: number;
}

export interface ErrorCode {
readonly pos: ErrorPosition;
readonly logId: string | null;
readonly msg: string | null;
}
1 change: 1 addition & 0 deletions packages/abi-coder/src/utils/transpile-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export function transpileAbi(abi) {
loggedTypes,
messagesTypes: abi.messagesTypes,
configurables,
errorCodes: abi.errorCodes,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
9 changes: 8 additions & 1 deletion packages/abi-typegen/src/abi/Abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { normalizeString } from '@fuel-ts/utils';

import type { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum';
import type { IConfigurable } from '../types/interfaces/IConfigurable';
import type { IErrorCode } from '../types/interfaces/IErrorCode';
import type { IFunction } from '../types/interfaces/IFunction';
import type { IType } from '../types/interfaces/IType';
import type { JsonAbiOld } from '../types/interfaces/JsonAbi';
import type { JsonAbi } from '../types/interfaces/JsonAbiNew';
import { parseErrorCodes } from '../utils/parseErrorCodes';
import { parseFunctions } from '../utils/parseFunctions';
import { parseTypes } from '../utils/parseTypes';
import { transpileAbi } from '../utils/transpile-abi';
Expand All @@ -33,6 +35,7 @@ export class Abi {
public types: IType[];
public functions: IFunction[];
public configurables: IConfigurable[];
public errorCodes?: IErrorCode[];

constructor(params: {
filepath: string;
Expand Down Expand Up @@ -73,11 +76,12 @@ export class Abi {
this.storageSlotsContents = storageSlotsContents;
this.outputDir = outputDir;

const { types, functions, configurables } = this.parse();
const { types, functions, configurables, errorCodes } = this.parse();

this.types = types;
this.functions = functions;
this.configurables = configurables;
this.errorCodes = errorCodes;

this.computeCommonTypesInUse();
}
Expand All @@ -88,18 +92,21 @@ export class Abi {
types: rawAbiTypes,
functions: rawAbiFunctions,
configurables: rawAbiConfigurables,
errorCodes: rawErrorCodes,
} = transpiled;

const types = parseTypes({ rawAbiTypes });
const functions = parseFunctions({ rawAbiFunctions, types });
const configurables = rawAbiConfigurables.map(
(rawAbiConfigurable) => new Configurable({ types, rawAbiConfigurable })
);
const errorCodes = parseErrorCodes({ rawErrorCodes, types });

return {
types,
functions,
configurables,
errorCodes,
};
}

Expand Down
11 changes: 11 additions & 0 deletions packages/abi-typegen/src/abi/errors/ErrorCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { IErrorCode } from '../../types/interfaces/IErrorCode';

export class ErrorCode {
public code: string;
public value: IErrorCode['value'];

constructor(params: IErrorCode) {
this.code = params.code;
this.value = params.value;
}
}
6 changes: 6 additions & 0 deletions packages/abi-typegen/src/types/interfaces/IErrorCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { JsonAbiErrorCode } from './JsonAbi';

export interface IErrorCode {
code: string;
value: JsonAbiErrorCode;
}
12 changes: 12 additions & 0 deletions packages/abi-typegen/src/types/interfaces/JsonAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface JsonAbiOld {
readonly functions: readonly JsonAbiFunction[];
readonly messagesTypes: readonly JsonAbiMessagesType[];
readonly configurables: readonly JsonAbiConfigurable[];
readonly errorCodes?: Record<string, JsonAbiErrorCode>;
readonly encoding?: string;
}

Expand Down Expand Up @@ -55,3 +56,14 @@ export interface JsonAbiConfigurable {
configurableType: JsonAbiArgument;
offset: number;
}

export interface JsonAbiErrorCode {
pos: {
pkg: string;
file: string;
line: number;
column: number;
};
logId: string | null;
msg: string | null;
}
14 changes: 14 additions & 0 deletions packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface JsonAbi {
readonly loggedTypes: readonly LoggedType[];
readonly messagesTypes: readonly MessageType[];
readonly configurables: readonly Configurable[];
readonly errorCodes?: Record<string, ErrorCode>;
}

export interface ConcreteType {
Expand Down Expand Up @@ -99,3 +100,16 @@ export interface Configurable {
readonly concreteTypeId: string;
readonly offset: number;
}

export interface ErrorPosition {
pkg: string;
file: string;
line: number;
column: number;
}

export interface ErrorCode {
readonly pos: ErrorPosition;
readonly logId: string | null;
readonly msg: string | null;
}
6 changes: 6 additions & 0 deletions packages/abi-typegen/src/utils/makeErrorCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ErrorCode } from '../abi/errors/ErrorCode';
import type { IErrorCode } from '../types/interfaces/IErrorCode';

export function makeErrorCode(params: IErrorCode) {
return new ErrorCode(params);
}
18 changes: 18 additions & 0 deletions packages/abi-typegen/src/utils/parseErrorCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ErrorCode } from '../abi/errors/ErrorCode';
import type { IType } from '../types/interfaces/IType';
import type { JsonAbiErrorCode } from '../types/interfaces/JsonAbi';

import { makeErrorCode } from './makeErrorCodes';

export function parseErrorCodes(params: {
types: IType[];
rawErrorCodes?: Record<string, JsonAbiErrorCode>;
}) {
// const { types, rawErrorCodes } = params;
const { rawErrorCodes } = params;
const errorCodes: ErrorCode[] = Object.entries(rawErrorCodes ?? {}).map(([code, value]) =>
makeErrorCode({ code, value })
);

return errorCodes;
}
1 change: 1 addition & 0 deletions packages/abi-typegen/src/utils/transpile-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export function transpileAbi(abi) {
loggedTypes,
messagesTypes: abi.messagesTypes,
configurables,
errorCodes: abi.errorCodes,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 4 additions & 0 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2615,20 +2615,24 @@ export default class Provider {
): FuelError {
let logs: DecodedLogs['logs'] = [];
let groupedLogs: DecodedLogs['groupedLogs'] = {};
let abis: JsonAbisFromAllCalls | undefined;

if (transactionRequest.type === TransactionType.Script && transactionRequest.abis) {
({ logs, groupedLogs } = getAllDecodedLogs({
receipts,
mainAbi: transactionRequest.abis.main,
externalAbis: transactionRequest.abis.otherContractsAbis,
}));

abis = transactionRequest.abis;
}

return extractTxError({
logs,
groupedLogs,
receipts,
statusReason: reason,
abis,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export class TransactionResponse {
};

let { logs, groupedLogs }: DecodedLogs = { logs: [], groupedLogs: {} };
let abis: JsonAbisFromAllCalls | undefined;

if (this.abis) {
({ logs, groupedLogs } = getAllDecodedLogs({
Expand All @@ -492,6 +493,8 @@ export class TransactionResponse {

transactionResult.logs = logs;
transactionResult.groupedLogs = groupedLogs;

abis = this.abis;
}

const { receipts } = transactionResult;
Expand All @@ -505,6 +508,7 @@ export class TransactionResponse {
statusReason: reason,
logs,
groupedLogs,
abis,
});
}

Expand Down
Loading
Loading