Skip to content

Commit

Permalink
cleanup error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Jan 5, 2023
1 parent 12a48bd commit ff9b453
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/sdk/src/evm/common/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class TransactionError extends Error {
raw: string,
functionInfo: FunctionInfo | undefined,
) {
let builtErrorMsg = "Contract transaction failed\n\n";
let builtErrorMsg = "\n| Contract transaction failed |\n\n";
builtErrorMsg += `Message: ${reason}`;
builtErrorMsg += "\n\n| Transaction info |\n";
builtErrorMsg += withSpaces("from", from);
Expand Down Expand Up @@ -320,9 +320,6 @@ export class TransactionError extends Error {
// ignore if can't parse URL
}
builtErrorMsg += "\n\n";
builtErrorMsg +=
"Need help with this error? Join our community: https://discord.gg/thirdweb";
builtErrorMsg += "\n\n\n\n";
builtErrorMsg += "| Raw error |";
builtErrorMsg += "\n\n";
builtErrorMsg += raw;
Expand Down Expand Up @@ -401,9 +398,19 @@ export async function convertToTWError(
// not sure what this is, just throw it back
raw = error.toString();
}
const reason =
let reason =
parseMessageParts(/.*?"message[^a-zA-Z0-9]*([^"\\]*).*?/, raw) ||
parseMessageParts(/.*?"reason[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
if (reason && reason.toLowerCase().includes("cannot estimate gas")) {
// the error might be in the next reason block
const nextReason = parseMessageParts(
/.*?"reason[^a-zA-Z0-9]*([^"\\]*).*?/,
raw.slice(raw.indexOf(reason) + reason.length),
);
if (nextReason) {
reason = nextReason;
}
}
const data = parseMessageParts(/.*?"data[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
const rpcUrl = parseMessageParts(/.*?"url[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
let from = parseMessageParts(/.*?"from[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
Expand Down

0 comments on commit ff9b453

Please sign in to comment.