Skip to content

Commit c4af185

Browse files
committed
improve unexpected exit error parsing
1 parent 3df6ddf commit c4af185

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

packages/cli-v3/src/entryPoints/deploy-run-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ class ProdWorker {
795795
id: execution.run.id,
796796
ok: false,
797797
retry: undefined,
798-
error: TaskRunProcess.parseExecuteError(error),
798+
error: TaskRunProcess.parseExecuteError(error, !this.runningInKubernetes),
799799
});
800800
} catch (error) {
801801
this.#failRun(message.lazyPayload.runId, error);

packages/cli-v3/src/executions/taskRunProcess.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { logger } from "../utilities/logger.js";
2323
import {
2424
CancelledProcessError,
2525
CleanupProcessError,
26-
getFriendlyErrorMessage,
26+
internalErrorFromUnexpectedExit,
2727
GracefulExitTimeoutError,
2828
UnexpectedExitError,
2929
} from "@trigger.dev/core/v3/errors";
@@ -386,7 +386,7 @@ export class TaskRunProcess {
386386
return this._childPid;
387387
}
388388

389-
static parseExecuteError(error: unknown): TaskRunInternalError {
389+
static parseExecuteError(error: unknown, dockerMode = false): TaskRunInternalError {
390390
if (error instanceof CancelledProcessError) {
391391
return {
392392
type: "INTERNAL_ERROR",
@@ -402,12 +402,7 @@ export class TaskRunProcess {
402402
}
403403

404404
if (error instanceof UnexpectedExitError) {
405-
return {
406-
type: "INTERNAL_ERROR",
407-
code: TaskRunErrorCodes.TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE,
408-
message: getFriendlyErrorMessage(error.code, error.signal, error.stderr),
409-
stackTrace: error.stderr,
410-
};
405+
return internalErrorFromUnexpectedExit(error, dockerMode);
411406
}
412407

413408
return {

packages/core/src/v3/errors.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -400,32 +400,37 @@ export function exceptionEventEnhancer(
400400
return exception;
401401
}
402402

403-
export function getFriendlyErrorMessage(
404-
code: number,
405-
signal: NodeJS.Signals | null,
406-
stderr: string | undefined,
403+
export function internalErrorFromUnexpectedExit(
404+
error: UnexpectedExitError,
407405
dockerMode = true
408-
) {
409-
if (code === 137) {
406+
): TaskRunInternalError {
407+
if (error.code === 137) {
410408
if (dockerMode) {
411-
return message(
412-
"Process ran out of memory! Try choosing a machine preset with more memory for this task."
413-
);
409+
return {
410+
type: "INTERNAL_ERROR",
411+
code: TaskRunErrorCodes.TASK_PROCESS_OOM_KILLED,
412+
};
414413
} else {
415-
// Note: containerState reason and message should be checked to clarify the error
416-
return message(
417-
"Process most likely ran out of memory, but we can't be certain. Try choosing a machine preset with more memory for this task."
418-
);
414+
// Note: containerState reason and message could be checked to clarify the error, maybe the task monitor should be allowed to override these
415+
return {
416+
type: "INTERNAL_ERROR",
417+
code: TaskRunErrorCodes.TASK_PROCESS_MAYBE_OOM_KILLED,
418+
};
419419
}
420420
}
421421

422-
if (stderr?.includes("OOMErrorHandler")) {
423-
return message(
424-
"Process ran out of memory! Try choosing a machine preset with more memory for this task."
425-
);
422+
if (error.stderr?.includes("OOMErrorHandler")) {
423+
return {
424+
type: "INTERNAL_ERROR",
425+
code: TaskRunErrorCodes.TASK_PROCESS_OOM_KILLED,
426+
};
426427
}
427428

428-
return message(`Process exited with code ${code}.`);
429+
return {
430+
type: "INTERNAL_ERROR",
431+
code: TaskRunErrorCodes.TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE,
432+
message: `Process exited with code ${error.code} after signal ${error.signal}.`,
433+
};
429434
}
430435

431436
export function serializeIndexingError(error: unknown, stderr?: string): DeploymentErrorData {

0 commit comments

Comments
 (0)