From 80aa2884a3aeb8b6f64080d665671e22a5c453cd Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 10 Jan 2019 00:36:42 -0800 Subject: Linter --- packages/base-contract/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'packages/base-contract/src/index.ts') diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 2471ded92..f14b9a96a 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -86,9 +86,13 @@ export class BaseContract { } protected static _throwIfRevertWithReasonCallResult(rawCallResult: string): void { if (rawCallResult.slice(REVERT_ERROR_SELECTOR_OFFSET, REVERT_ERROR_SELECTOR_END) === REVERT_ERROR_SELECTOR) { - const revertReason = AbiEncoder.create('(string)').decodeAsArray( + const revertReasonArray = AbiEncoder.create('(string)').decodeAsArray( ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH), - )[0]; + ); + if (revertReasonArray.length !== 1) { + throw new Error(`Cannot safely decode revert reason: Expected an array with one element, got ${revertReasonArray}`); + } + const revertReason = revertReasonArray[0]; throw new Error(revertReason); } } -- cgit v1.2.3