Skip to content

Commit

Permalink
fix decode revert reason on relayCall.view (#636)
Browse files Browse the repository at this point in the history
different nodes report differently the revert reason (its hard to report
it, since its a function that returns a struct, but revert reason is
encoded differently.)
this fix adds support to kotti's way of reporting the revert reason
(support both "revert" and "reverted" in both err.data.message and
res.error.message, and defensively protect again non-string data ..

Co-authored-by: Alex Forshtat <forshtat1@gmail.com>
  • Loading branch information
drortirosh and forshtat authored May 12, 2021
1 parent bdce42a commit f433ce9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/common/src/ContractInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,14 @@ export class ContractInteractor {
// decode revert from rpc response.
//
_decodeRevertFromResponse (err?: { message?: string, data?: any }, res?: { error?: any, result?: string }): string | null {
const matchGanache = res?.error?.message?.match(/: revert (.*)/)
let matchGanache = err?.data?.message?.toString().match(/: revert(?:ed)? (.*)/)
if (matchGanache == null) {
matchGanache = res?.error?.message?.toString().match(/: revert(?:ed)? (.*)/)
}
if (matchGanache != null) {
return matchGanache[1]
}
const m = err?.data?.match(/(0x08c379a0\S*)/)
const m = err?.data?.toString().match(/(0x08c379a0\S*)/)
if (m != null) {
return decodeRevertReason(m[1])
}
Expand Down

0 comments on commit f433ce9

Please # to comment.