Skip to content

Commit e22c321

Browse files
authored
fix(engine) truncate errors before storing them on a run and waitpoint output (#2552)
1 parent 59df4af commit e22c321

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,8 @@ export class RunAttemptSystem {
14761476
return startSpan(this.$.tracer, "permanentlyFailRun", async (span) => {
14771477
const status = runStatusFromError(error, latestSnapshot.environmentType);
14781478

1479+
const truncatedError = this.#truncateTaskRunError(error);
1480+
14791481
//run permanently failed
14801482
const run = await prisma.taskRun.update({
14811483
where: {
@@ -1484,7 +1486,7 @@ export class RunAttemptSystem {
14841486
data: {
14851487
status,
14861488
completedAt: failedAt,
1487-
error,
1489+
error: truncatedError,
14881490
},
14891491
select: {
14901492
id: true,
@@ -1546,7 +1548,7 @@ export class RunAttemptSystem {
15461548

15471549
await this.waitpointSystem.completeWaitpoint({
15481550
id: run.associatedWaitpoint.id,
1549-
output: { value: JSON.stringify(error), isError: true },
1551+
output: { value: JSON.stringify(truncatedError), isError: true },
15501552
});
15511553

15521554
this.$.eventBus.emit("runFailed", {
@@ -1892,6 +1894,19 @@ export class RunAttemptSystem {
18921894
});
18931895
}
18941896
}
1897+
1898+
#truncateTaskRunError(error: TaskRunError): TaskRunError {
1899+
if (error.type !== "BUILT_IN_ERROR") {
1900+
return error;
1901+
}
1902+
1903+
return {
1904+
type: "BUILT_IN_ERROR",
1905+
name: truncateString(error.name, 1024),
1906+
message: truncateString(error.message, 1024 * 16), // 16kb
1907+
stackTrace: truncateString(error.stackTrace, 1024 * 16), // 16kb
1908+
};
1909+
}
18951910
}
18961911

18971912
export function safeParseGitMeta(git: unknown): GitMeta | undefined {
@@ -1901,3 +1916,11 @@ export function safeParseGitMeta(git: unknown): GitMeta | undefined {
19011916
}
19021917
return undefined;
19031918
}
1919+
1920+
function truncateString(str: string | undefined, maxLength: number): string {
1921+
if (!str) {
1922+
return "";
1923+
}
1924+
1925+
return str.slice(0, maxLength);
1926+
}

0 commit comments

Comments
 (0)