Skip to content

Commit 2deedb6

Browse files
committed
wrap error
1 parent 584b1a2 commit 2deedb6

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/utils/error.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { ethers } from "ethers";
22
import { stringify } from "thirdweb/utils";
33
import { isEthersErrorCode } from "./ethers";
44

5-
/**
6-
* Pretty print an error with an optional contextual prefix ("[RpcError] \<response from RPC\>").
7-
*/
8-
export const prettifyError = (
9-
error: unknown,
10-
prefix?: "RPC" | "Bundler",
11-
): string =>
12-
`[${prefix}] ${error instanceof Error ? error.message : stringify(error)}`;
5+
export const wrapError = (error: unknown, prefix: "RPC" | "Bundler") =>
6+
new Error(`[${prefix}] ${prettifyError(error)}`);
7+
8+
export const prettifyError = (error: unknown): string =>
9+
error instanceof Error ? error.message : stringify(error);
1310

1411
const _parseMessage = (error: unknown): string | null => {
1512
return error && typeof error === "object" && "message" in error

src/worker/tasks/sendTransactionWorker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
isNonceAlreadyUsedError,
3939
isReplacementGasFeeTooLow,
4040
prettifyError,
41+
wrapError,
4142
} from "../../utils/error";
4243
import { getChecksumAddress } from "../../utils/primitiveTypes";
4344
import { recordMetrics } from "../../utils/prometheus";
@@ -249,7 +250,7 @@ const _sendUserOp = async (
249250
return {
250251
...queuedTransaction,
251252
status: "errored",
252-
errorMessage: prettifyError(e, "Bundler"),
253+
errorMessage: wrapError(e, "Bundler").message,
253254
} satisfies ErroredTransaction;
254255
}
255256

@@ -326,7 +327,7 @@ const _sendTransaction = async (
326327
return {
327328
...queuedTransaction,
328329
status: "errored",
329-
errorMessage: prettifyError(e, "RPC"),
330+
errorMessage: wrapError(e, "RPC").message,
330331
} satisfies ErroredTransaction;
331332
}
332333

@@ -380,7 +381,7 @@ const _sendTransaction = async (
380381
const gasPrice =
381382
populatedTransaction.gasPrice ?? populatedTransaction.maxFeePerGas;
382383

383-
let errorMessage = prettifyError(e, "RPC");
384+
let errorMessage = prettifyError(e);
384385
if (gasPrice) {
385386
const { gas, value = 0n } = populatedTransaction;
386387
const { name, nativeCurrency } = await getChainMetadata(chain);
@@ -394,7 +395,7 @@ const _sendTransaction = async (
394395
} satisfies ErroredTransaction;
395396
}
396397

397-
throw prettifyError(e, "RPC");
398+
throw wrapError(e, "RPC");
398399
}
399400

400401
await addSentNonce(chainId, from, nonce);
@@ -480,7 +481,7 @@ const _resendTransaction = async (
480481
job.log("A pending transaction exists with >= gas fees. Do not resend.");
481482
return null;
482483
}
483-
throw error;
484+
throw wrapError(error, "RPC");
484485
}
485486

486487
return {

0 commit comments

Comments
 (0)