From be5ec2d327a503b2e5fc0f37c47eee9e828f8e23 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Thu, 1 Feb 2024 03:19:20 -0500 Subject: [PATCH] Allow override keyword in human-readable ABI and improve error messages (#4514, #4548). --- src.ts/abi/fragments.ts | 11 +++++++---- src.ts/abi/interface.ts | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src.ts/abi/fragments.ts b/src.ts/abi/fragments.ts index 6fce9a798..f18346543 100644 --- a/src.ts/abi/fragments.ts +++ b/src.ts/abi/fragments.ts @@ -121,11 +121,11 @@ function setify(items: Array): ReadonlySet { return Object.freeze(result); } -const _kwVisibDeploy = "external public payable"; +const _kwVisibDeploy = "external public payable override"; const KwVisibDeploy = setify(_kwVisibDeploy.split(" ")); // Visibility Keywords -const _kwVisib = "constant external internal payable private public pure view"; +const _kwVisib = "constant external internal payable private public pure view override"; const KwVisib = setify(_kwVisib.split(" ")); const _kwTypes = "constructor error event fallback function receive struct"; @@ -218,7 +218,10 @@ class TokenString { // Pops and returns the value of the next token if it is `type`; throws if out of tokens popType(type: string): string { - if (this.peek().type !== type) { throw new Error(`expected ${ type }; got ${ JSON.stringify(this.peek()) }`); } + if (this.peek().type !== type) { + const top = this.peek(); + throw new Error(`expected ${ type }; got ${ top.type } ${ JSON.stringify(top.text) }`); + } return this.pop().text; } @@ -471,7 +474,7 @@ function consumeGas(tokens: TokenString): null | bigint { function consumeEoi(tokens: TokenString): void { if (tokens.length) { - throw new Error(`unexpected tokens: ${ tokens.toString() }`); + throw new Error(`unexpected tokens at offset ${ tokens.offset }: ${ tokens.toString() }`); } } diff --git a/src.ts/abi/interface.ts b/src.ts/abi/interface.ts index e3e0d7bdc..113364c3c 100644 --- a/src.ts/abi/interface.ts +++ b/src.ts/abi/interface.ts @@ -342,8 +342,8 @@ export class Interface { for (const a of abi) { try { frags.push(Fragment.from(a)); - } catch (error) { - console.log("EE", error); + } catch (error: any) { + console.log(`[Warning] Invalid Fragment ${ JSON.stringify(a) }:`, error.message); } }