Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/queue-processors/base-queue-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ export abstract class BaseQueueProcessor<
return { status: "success" };
} catch (err) {
const decision = this.getRetryDecision(err, job);
this.logProcessingError(jobId, err, decision);
try {
this.logProcessingError(jobId, err, decision);
} catch (logErr) {
console.error(
`[job:${jobId}] logProcessingError threw`,
logErr instanceof Error ? logErr.message : String(logErr),
);
}
if (decision.shouldRetry) {
try {
const attempts = await this.retryJob(job, decision.options);
Expand Down
21 changes: 19 additions & 2 deletions src/utils/log-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
const JSON_INDENT = 2;

function getCircularReplacer(): (key: string, value: unknown) => unknown {
const seen = new WeakSet<object>();
return (_key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value as object)) {
return "[Circular]";
}
seen.add(value as object);
}
return value;
};
}

export function serializeError(detail: unknown): string {
if (detail instanceof Error) {
const { name, message, ...rest } = detail as Error &
Record<string, unknown>;
return JSON.stringify({ name, message, ...rest }, null, JSON_INDENT);
return JSON.stringify(
{ name, message, ...rest },
getCircularReplacer(),
JSON_INDENT,
);
}
return JSON.stringify(detail, null, JSON_INDENT);
return JSON.stringify(detail, getCircularReplacer(), JSON_INDENT);
}
Loading