Skip to content

Commit bfb62ad

Browse files
authored
feat: implement support for new ABI error codes (#3894)
1 parent 34b77dc commit bfb62ad

File tree

31 files changed

+484
-92
lines changed

31 files changed

+484
-92
lines changed

.changeset/hot-results-happen.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@fuel-ts/transactions": patch
3+
"@fuel-ts/abi-typegen": patch
4+
"@fuel-ts/abi-coder": patch
5+
"@fuel-ts/versions": patch
6+
"@fuel-ts/account": patch
7+
"@fuel-ts/program": patch
8+
"@internal/forc": patch
9+
---
10+
11+
feat: implement support for new ABI error codes

apps/create-fuels-counter-guide/fuel-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
channel = "testnet"
33

44
[components]
5-
forc = "0.68.6"
5+
forc = "0.68.7"
66
fuel-core = "0.43.1"

internal/forc/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.68.6
1+
0.68.7

packages/abi-coder/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export { Coder, InputValue, DecodedValue } from './encoding/coders/AbstractCoder
22
export type { FunctionFragment } from './FunctionFragment';
33
export * from './encoding/coders';
44
export { Interface } from './Interface';
5-
export type { JsonAbi } from './types/JsonAbiNew';
5+
export type { JsonAbi, ErrorCode as JsonAbiErrorCode } from './types/JsonAbiNew';
66
export {
77
SCRIPT_FIXED_SIZE,
88
INPUT_COIN_FIXED_SIZE,

packages/abi-coder/src/types/JsonAbiNew.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface JsonAbi {
1212
readonly loggedTypes: readonly LoggedType[];
1313
readonly messagesTypes: readonly MessageType[];
1414
readonly configurables: readonly Configurable[];
15+
readonly errorCodes?: Record<string, ErrorCode>;
1516
}
1617

1718
export interface ConcreteType {
@@ -99,3 +100,16 @@ export interface Configurable {
99100
readonly concreteTypeId: string;
100101
readonly offset: number;
101102
}
103+
104+
export interface ErrorPosition {
105+
pkg: string;
106+
file: string;
107+
line: number;
108+
column: number;
109+
}
110+
111+
export interface ErrorCode {
112+
readonly pos: ErrorPosition;
113+
readonly logId: string | null;
114+
readonly msg: string | null;
115+
}

packages/abi-coder/src/utils/transpile-abi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export function transpileAbi(abi) {
139139
loggedTypes,
140140
messagesTypes: abi.messagesTypes,
141141
configurables,
142+
errorCodes: abi.errorCodes,
142143
};
143144

144145
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/abi-typegen/src/abi/Abi.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { normalizeString } from '@fuel-ts/utils';
33

44
import type { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum';
55
import type { IConfigurable } from '../types/interfaces/IConfigurable';
6+
import type { IErrorCode } from '../types/interfaces/IErrorCode';
67
import type { IFunction } from '../types/interfaces/IFunction';
78
import type { IType } from '../types/interfaces/IType';
89
import type { JsonAbiOld } from '../types/interfaces/JsonAbi';
910
import type { JsonAbi } from '../types/interfaces/JsonAbiNew';
11+
import { parseErrorCodes } from '../utils/parseErrorCodes';
1012
import { parseFunctions } from '../utils/parseFunctions';
1113
import { parseTypes } from '../utils/parseTypes';
1214
import { transpileAbi } from '../utils/transpile-abi';
@@ -33,6 +35,7 @@ export class Abi {
3335
public types: IType[];
3436
public functions: IFunction[];
3537
public configurables: IConfigurable[];
38+
public errorCodes?: IErrorCode[];
3639

3740
constructor(params: {
3841
filepath: string;
@@ -73,11 +76,12 @@ export class Abi {
7376
this.storageSlotsContents = storageSlotsContents;
7477
this.outputDir = outputDir;
7578

76-
const { types, functions, configurables } = this.parse();
79+
const { types, functions, configurables, errorCodes } = this.parse();
7780

7881
this.types = types;
7982
this.functions = functions;
8083
this.configurables = configurables;
84+
this.errorCodes = errorCodes;
8185

8286
this.computeCommonTypesInUse();
8387
}
@@ -88,18 +92,21 @@ export class Abi {
8892
types: rawAbiTypes,
8993
functions: rawAbiFunctions,
9094
configurables: rawAbiConfigurables,
95+
errorCodes: rawErrorCodes,
9196
} = transpiled;
9297

9398
const types = parseTypes({ rawAbiTypes });
9499
const functions = parseFunctions({ rawAbiFunctions, types });
95100
const configurables = rawAbiConfigurables.map(
96101
(rawAbiConfigurable) => new Configurable({ types, rawAbiConfigurable })
97102
);
103+
const errorCodes = parseErrorCodes({ rawErrorCodes, types });
98104

99105
return {
100106
types,
101107
functions,
102108
configurables,
109+
errorCodes,
103110
};
104111
}
105112

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { IErrorCode } from '../../types/interfaces/IErrorCode';
2+
3+
export class ErrorCode {
4+
public code: string;
5+
public value: IErrorCode['value'];
6+
7+
constructor(params: IErrorCode) {
8+
this.code = params.code;
9+
this.value = params.value;
10+
}
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { JsonAbiErrorCode } from './JsonAbi';
2+
3+
export interface IErrorCode {
4+
code: string;
5+
value: JsonAbiErrorCode;
6+
}

packages/abi-typegen/src/types/interfaces/JsonAbi.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface JsonAbiOld {
88
readonly functions: readonly JsonAbiFunction[];
99
readonly messagesTypes: readonly JsonAbiMessagesType[];
1010
readonly configurables: readonly JsonAbiConfigurable[];
11+
readonly errorCodes?: Record<string, JsonAbiErrorCode>;
1112
readonly encoding?: string;
1213
}
1314

@@ -55,3 +56,14 @@ export interface JsonAbiConfigurable {
5556
configurableType: JsonAbiArgument;
5657
offset: number;
5758
}
59+
60+
export interface JsonAbiErrorCode {
61+
pos: {
62+
pkg: string;
63+
file: string;
64+
line: number;
65+
column: number;
66+
};
67+
logId: string | null;
68+
msg: string | null;
69+
}

0 commit comments

Comments
 (0)