Skip to content

Commit be5ec2d

Browse files
committed
Allow override keyword in human-readable ABI and improve error messages (ethers-io#4514, ethers-io#4548).
1 parent 98496bc commit be5ec2d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src.ts/abi/fragments.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ function setify(items: Array<string>): ReadonlySet<string> {
121121
return Object.freeze(result);
122122
}
123123

124-
const _kwVisibDeploy = "external public payable";
124+
const _kwVisibDeploy = "external public payable override";
125125
const KwVisibDeploy = setify(_kwVisibDeploy.split(" "));
126126

127127
// Visibility Keywords
128-
const _kwVisib = "constant external internal payable private public pure view";
128+
const _kwVisib = "constant external internal payable private public pure view override";
129129
const KwVisib = setify(_kwVisib.split(" "));
130130

131131
const _kwTypes = "constructor error event fallback function receive struct";
@@ -218,7 +218,10 @@ class TokenString {
218218

219219
// Pops and returns the value of the next token if it is `type`; throws if out of tokens
220220
popType(type: string): string {
221-
if (this.peek().type !== type) { throw new Error(`expected ${ type }; got ${ JSON.stringify(this.peek()) }`); }
221+
if (this.peek().type !== type) {
222+
const top = this.peek();
223+
throw new Error(`expected ${ type }; got ${ top.type } ${ JSON.stringify(top.text) }`);
224+
}
222225
return this.pop().text;
223226
}
224227

@@ -471,7 +474,7 @@ function consumeGas(tokens: TokenString): null | bigint {
471474

472475
function consumeEoi(tokens: TokenString): void {
473476
if (tokens.length) {
474-
throw new Error(`unexpected tokens: ${ tokens.toString() }`);
477+
throw new Error(`unexpected tokens at offset ${ tokens.offset }: ${ tokens.toString() }`);
475478
}
476479
}
477480

src.ts/abi/interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ export class Interface {
342342
for (const a of abi) {
343343
try {
344344
frags.push(Fragment.from(a));
345-
} catch (error) {
346-
console.log("EE", error);
345+
} catch (error: any) {
346+
console.log(`[Warning] Invalid Fragment ${ JSON.stringify(a) }:`, error.message);
347347
}
348348
}
349349

0 commit comments

Comments
 (0)