Skip to content

Commit 86ca363

Browse files
committed
Added throwable InternalError. Plus new TASK_DID_CONCURRENT_WAIT code
1 parent 4ce001e commit 86ca363

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

packages/core/src/v3/errors.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ import { links } from "./links.js";
1212
import { ExceptionEventProperties } from "./schemas/openTelemetry.js";
1313
import { assertExhaustive } from "../utils.js";
1414

15+
/**
16+
* If you throw this, it will get converted into an INTERNAL_ERROR
17+
*/
18+
export class InternalError extends Error {
19+
public readonly code: TaskRunErrorCodes;
20+
public readonly skipRetrying: boolean;
21+
22+
constructor({
23+
code,
24+
message,
25+
showStackTrace = true,
26+
skipRetrying = false,
27+
}: {
28+
code: TaskRunErrorCodes;
29+
message?: string;
30+
showStackTrace?: boolean;
31+
skipRetrying?: boolean;
32+
}) {
33+
super(`${code}: ${message ?? "No message"}`);
34+
this.name = "InternalError";
35+
this.code = code;
36+
this.message = message ?? "InternalError";
37+
38+
if (!showStackTrace) {
39+
this.stack = undefined;
40+
}
41+
42+
this.skipRetrying = skipRetrying;
43+
}
44+
}
45+
1546
export class AbortTaskRunError extends Error {
1647
constructor(message: string) {
1748
super(message);
@@ -31,14 +62,16 @@ export class TaskPayloadParsedError extends Error {
3162
}
3263
}
3364

34-
export class ConcurrentWaitError extends Error {
35-
constructor(message: string) {
36-
super(message);
37-
this.name = "ConcurrentWaitError";
65+
export function parseError(error: unknown): TaskRunError {
66+
if (error instanceof InternalError) {
67+
return {
68+
type: "INTERNAL_ERROR",
69+
code: error.code,
70+
message: error.message,
71+
stackTrace: error.stack ?? "",
72+
};
3873
}
39-
}
4074

41-
export function parseError(error: unknown): TaskRunError {
4275
if (error instanceof Error) {
4376
return {
4477
type: "BUILT_IN_ERROR",
@@ -175,6 +208,7 @@ export function shouldRetryError(error: TaskRunError): boolean {
175208
case "DISK_SPACE_EXCEEDED":
176209
case "TASK_RUN_HEARTBEAT_TIMEOUT":
177210
case "OUTDATED_SDK_VERSION":
211+
case "TASK_DID_CONCURRENT_WAIT":
178212
return false;
179213

180214
case "GRACEFUL_EXIT_TIMEOUT":
@@ -444,6 +478,14 @@ const prettyInternalErrors: Partial<
444478
href: links.docs.upgrade.beta,
445479
},
446480
},
481+
TASK_DID_CONCURRENT_WAIT: {
482+
message:
483+
"Parallel waits are not supported, e.g. using Promise.all() around our wait functions.",
484+
link: {
485+
name: "Read the docs for solutions",
486+
href: links.docs.troubleshooting.concurrentWaits,
487+
},
488+
},
447489
};
448490

449491
const getPrettyTaskRunError = (code: TaskRunInternalError["code"]): TaskRunInternalError => {

0 commit comments

Comments
 (0)