Skip to content

Commit aee555a

Browse files
committed
some errors should never be retried
1 parent 9f6696d commit aee555a

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

apps/webapp/app/v3/services/completeAttempt.server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
TaskRunSuccessfulExecutionResult,
99
flattenAttributes,
1010
sanitizeError,
11+
shouldRetryError,
1112
} from "@trigger.dev/core/v3";
1213
import { $transaction, PrismaClientOrTransaction } from "~/db.server";
1314
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
@@ -216,7 +217,11 @@ export class CompleteAttemptService extends BaseService {
216217

217218
const environment = env ?? (await this.#getEnvironment(execution.environment.id));
218219

219-
if (completion.retry !== undefined && taskRunAttempt.number < MAX_TASK_RUN_ATTEMPTS) {
220+
if (
221+
shouldRetryError(completion.error) &&
222+
completion.retry !== undefined &&
223+
taskRunAttempt.number < MAX_TASK_RUN_ATTEMPTS
224+
) {
220225
return await this.#retryAttempt({
221226
execution,
222227
executionRetry: completion.retry,

packages/core/src/v3/errors.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { TaskMetadataFailedToParseData } from "./schemas/messages.js";
1111
import { links } from "./links.js";
1212
import { ExceptionEventProperties } from "./schemas/openTelemetry.js";
13+
import { assertExhaustive } from "../utils.js";
1314

1415
export class AbortTaskRunError extends Error {
1516
constructor(message: string) {
@@ -137,6 +138,55 @@ export function sanitizeError(error: TaskRunError): TaskRunError {
137138
}
138139
}
139140

141+
export function shouldRetryError(error: TaskRunError): boolean {
142+
switch (error.type) {
143+
case "INTERNAL_ERROR": {
144+
switch (error.code) {
145+
case "COULD_NOT_FIND_EXECUTOR":
146+
case "COULD_NOT_FIND_TASK":
147+
case "COULD_NOT_IMPORT_TASK":
148+
case "CONFIGURED_INCORRECTLY":
149+
case "TASK_ALREADY_RUNNING":
150+
case "TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE":
151+
case "TASK_PROCESS_SIGKILL_TIMEOUT":
152+
case "TASK_PROCESS_OOM_KILLED":
153+
case "TASK_PROCESS_MAYBE_OOM_KILLED":
154+
case "TASK_RUN_CANCELLED":
155+
case "TASK_OUTPUT_ERROR":
156+
case "MAX_DURATION_EXCEEDED":
157+
case "DISK_SPACE_EXCEEDED":
158+
return false;
159+
160+
case "GRACEFUL_EXIT_TIMEOUT":
161+
case "HANDLE_ERROR_ERROR":
162+
case "IMPORT_PAYLOAD_ERROR":
163+
case "POD_EVICTED":
164+
case "POD_UNKNOWN_ERROR":
165+
case "TASK_EXECUTION_ABORTED":
166+
case "TASK_EXECUTION_FAILED":
167+
case "TASK_RUN_CRASHED":
168+
case "TASK_RUN_HEARTBEAT_TIMEOUT":
169+
return true;
170+
171+
default:
172+
assertExhaustive(error.code);
173+
}
174+
}
175+
case "STRING_ERROR": {
176+
return true;
177+
}
178+
case "BUILT_IN_ERROR": {
179+
return true;
180+
}
181+
case "CUSTOM_ERROR": {
182+
return true;
183+
}
184+
default: {
185+
assertExhaustive(error);
186+
}
187+
}
188+
}
189+
140190
export function correctErrorStackTrace(
141191
stackTrace: string,
142192
projectDir?: string,

0 commit comments

Comments
 (0)