From 5a9fb0024f18ed2606551994166b2ff96cdecfd4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 25 Jul 2026 12:38:57 -0400 Subject: [PATCH] fix: Immediately stop retrying malformed imports --- server/queues/tasks/APIImportTask.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/queues/tasks/APIImportTask.ts b/server/queues/tasks/APIImportTask.ts index 16b03a6342..bfdd0a3b7e 100644 --- a/server/queues/tasks/APIImportTask.ts +++ b/server/queues/tasks/APIImportTask.ts @@ -1,5 +1,6 @@ import type { JobOptions } from "bull"; import { chunk, truncate, uniqBy } from "es-toolkit/compat"; +import httpErrors from "http-errors"; import { Fragment, Node } from "prosemirror-model"; import type { WhereOptions } from "sequelize"; import { Transaction } from "sequelize"; @@ -99,10 +100,27 @@ export default abstract class APIImportTask< await importTask.save(); } + if (this.isNonRetryable(err)) { + await this.onFailed({ importTaskId }); + } + throw err; // throw error for retry. } } + /** + * Whether a failure is deterministic and therefore not worth retrying. A + * 4xx-class error raised by our own error factories signals invalid source + * data (a missing file in an export, an unparseable document) rather than a + * transient problem such as a network or storage blip. + * + * @param err The error thrown while performing the task. + * @returns true when retrying the task cannot succeed. + */ + private isNonRetryable(err: unknown): boolean { + return httpErrors.isHttpError(err) && err.status >= 400 && err.status < 500; + } + /** * Handle failure when all attempts of APIImportTask has failed. *