Skip to content

Commit c16b97b

Browse files
farhanW3arcoraven
andauthored
Fix: Worker Error Reporting (#480)
* throwing Error for Worker onError hook to log right message * more errors --------- Co-authored-by: Phillip Ho <arcoraven@gmail.com>
1 parent b90de6b commit c16b97b

File tree

10 files changed

+22
-23
lines changed

10 files changed

+22
-23
lines changed

src/server/routes/chain/get.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ export async function getChainData(fastify: FastifyInstance) {
7777
}
7878

7979
if (!chainData) {
80-
const error = createCustomError(
80+
throw createCustomError(
8181
"Chain not found",
8282
StatusCodes.NOT_FOUND,
8383
"ChainNotFound",
8484
);
85-
throw error;
8685
}
8786

8887
const minimizeChainData = minimizeChain(chainData);

src/server/routes/contract/subscriptions/getContractIndexedBlockRange.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ export async function getContractIndexedBlockRange(fastify: FastifyInstance) {
5959
});
6060

6161
if (!result.fromBlock || !result.toBlock) {
62-
const error = createCustomError(
62+
throw createCustomError(
6363
`No logs found for chainId: ${chainId}, contractAddress: ${standardizedContractAddress}`,
6464
StatusCodes.NOT_FOUND,
6565
"LOG_NOT_FOUND",
6666
);
67-
throw error;
6867
}
6968

7069
reply.status(StatusCodes.OK).send({

src/server/routes/transaction/blockchain/getUserOpReceipt.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export async function getUserOpReceipt(fastify: FastifyInstance) {
101101
}),
102102
});
103103
if (!resp.ok) {
104-
throw `Unexpected status ${resp.status} - ${await resp.text()}`;
104+
throw new Error(
105+
`Unexpected status ${resp.status} - ${await resp.text()}`,
106+
);
105107
}
106108

107109
const json = await resp.json();

src/server/routes/transaction/getAll.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,17 @@ export async function getAllTx(fastify: FastifyInstance) {
115115
const { page, limit } = request.query;
116116

117117
if (isNaN(parseInt(page, 10))) {
118-
const customError = createCustomError(
118+
throw createCustomError(
119119
"Page must be a number",
120120
StatusCodes.BAD_REQUEST,
121121
"BAD_REQUEST",
122122
);
123-
throw customError;
124123
} else if (isNaN(parseInt(limit, 10))) {
125-
const customError = createCustomError(
124+
throw createCustomError(
126125
"Limit must be a number",
127126
StatusCodes.BAD_REQUEST,
128127
"BAD_REQUEST",
129128
);
130-
throw customError;
131129
}
132130

133131
const { transactions, totalCount } = await getAllTxs({

src/server/routes/transaction/getAllDeployedContracts.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,17 @@ export async function getAllDeployedContracts(fastify: FastifyInstance) {
9494
const { page, limit } = request.query;
9595

9696
if (isNaN(parseInt(page, 10))) {
97-
const customError = createCustomError(
97+
throw createCustomError(
9898
"Page must be a number",
9999
StatusCodes.BAD_REQUEST,
100100
"BAD_REQUEST",
101101
);
102-
throw customError;
103102
} else if (isNaN(parseInt(limit, 10))) {
104-
const customError = createCustomError(
103+
throw createCustomError(
105104
"Limit must be a number",
106105
StatusCodes.BAD_REQUEST,
107106
"BAD_REQUEST",
108107
);
109-
throw customError;
110108
}
111109
const { transactions, totalCount } = await getAllTxs({
112110
page: parseInt(page, 10),

src/server/routes/transaction/status.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ export async function checkTxStatus(fastify: FastifyInstance) {
8282
const returnData = await getTxById({ queueId });
8383

8484
if (!returnData) {
85-
const error = createCustomError(
85+
throw createCustomError(
8686
`Transaction not found with queueId ${queueId}`,
8787
StatusCodes.NOT_FOUND,
8888
"TX_NOT_FOUND",
8989
);
90-
throw error;
9190
}
9291

9392
reply.status(StatusCodes.OK).send({

src/server/routes/transaction/syncRetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export async function syncRetryTransaction(fastify: FastifyInstance) {
125125
try {
126126
txResponse = await signer.sendTransaction(txRequest);
127127
if (!txResponse) {
128-
throw "Missing transaction response.";
128+
throw new Error("Missing transaction response.");
129129
}
130130
} catch (e) {
131131
const errorMessage = await parseTxError(tx, e);

src/server/utils/simulateTx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const simulateRaw = async (tx: InputTransaction) => {
3636
from: tx.fromAddress,
3737
});
3838
} catch (e: any) {
39-
throw e?.message || e.toString();
39+
throw new Error(e?.message || e.toString());
4040
}
4141
};
4242

src/worker/queues/workers.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@ export const logWorkerEvents = (worker: Worker) => {
66
worker.on("active", (job: Job) => {
77
logger({
88
level: "debug",
9-
message: `Processing job ${job.id}`,
9+
message: `[${worker.name}] Processing: ${job.id}`,
1010
service: "worker",
1111
});
1212
});
1313
worker.on("completed", (job: Job) => {
1414
logger({
1515
level: "debug",
16-
message: `[${worker.name}] Job ${job.id} has completed!`,
16+
message: `[${worker.name}] Completed: ${job.id}`,
1717
service: "worker",
1818
});
1919
});
2020
worker.on("failed", (job: Job | undefined, err: Error) => {
2121
logger({
2222
level: "error",
23-
message: `[${worker.name}] Job ${job?.id ?? "?"} has failed with ${
24-
err.message
25-
} ${env.NODE_ENV === "development" ? err.stack : ""}`,
23+
message: `[${worker.name}] Failed: ${
24+
job?.id ?? "<no job ID>"
25+
} with error: ${err.message} ${
26+
env.NODE_ENV === "development" ? err.stack : ""
27+
}`,
2628
service: "worker",
2729
});
2830
});

src/worker/tasks/webhookWorker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ const handleWebhook: Processor<any, void, string> = async (
2020
}
2121

2222
if (resp && !resp.ok) {
23-
throw `Received status ${resp.status} from webhook ${webhook.url}.`;
23+
throw new Error(
24+
`Received status ${resp.status} from webhook ${webhook.url}.`,
25+
);
2426
}
2527
};
2628

0 commit comments

Comments
 (0)