Skip to content

Commit c2595f4

Browse files
committed
Improve the error experience around deadlocks
1 parent fe3025a commit c2595f4

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

apps/webapp/app/components/runs/v3/SpanEvents.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ export function SpanEventError({
8383
time={spanEvent.time}
8484
titleClassName="text-rose-500"
8585
/>
86-
{enhancedException.message && <Callout variant="error">{enhancedException.message}</Callout>}
86+
{enhancedException.message && (
87+
<Callout variant="error">
88+
<pre className="text-wrap font-sans text-sm font-normal text-rose-200">
89+
{enhancedException.message}
90+
</pre>
91+
</Callout>
92+
)}
8793
{enhancedException.link &&
8894
(enhancedException.link.magic === "CONTACT_FORM" ? (
8995
<Feedback

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,13 @@ function RunError({ error }: { error: TaskRunError }) {
808808
return (
809809
<div className="flex flex-col gap-2 rounded-sm border border-rose-500/50 px-3 pb-3 pt-2">
810810
<Header3 className="text-rose-500">{name}</Header3>
811-
{enhancedError.message && <Callout variant="error">{enhancedError.message}</Callout>}
811+
{enhancedError.message && (
812+
<Callout variant="error">
813+
<pre className="text-wrap font-sans text-sm font-normal text-rose-200">
814+
{enhancedError.message}
815+
</pre>
816+
</Callout>
817+
)}
812818
{enhancedError.link &&
813819
(enhancedError.link.magic === "CONTACT_FORM" ? (
814820
<Feedback

apps/webapp/app/runEngine/concerns/runChainStates.server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ To fix this, you can:
268268
1. Enable releaseConcurrencyOnWaitpoint on the queue
269269
2. Use a different queue for the child task
270270
3. Increase the concurrency limits
271-
4. Use trigger() instead of triggerAndWait() if you don't need to wait
272-
273-
Learn more about concurrency and deadlocks at https://trigger.dev/docs/queue-concurrency`;
271+
4. Use trigger() instead of triggerAndWait() if you don't need to wait`;
274272
}
275273
}

packages/core/src/v3/apiClient/errors.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,32 @@ export class ApiError extends Error {
2828
}
2929

3030
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
31-
const msg = error?.message
31+
const errorMessage = error?.message
3232
? typeof error.message === "string"
3333
? error.message
3434
: JSON.stringify(error.message)
35+
: typeof error === "string"
36+
? error
3537
: error
3638
? JSON.stringify(error)
37-
: message;
39+
: undefined;
3840

39-
if (status && msg) {
40-
return `${status} ${msg}`;
41+
if (errorMessage) {
42+
return errorMessage;
4143
}
44+
45+
if (status && message) {
46+
return `${status} ${message}`;
47+
}
48+
4249
if (status) {
4350
return `${status} status code (no body)`;
4451
}
45-
if (msg) {
46-
return msg;
52+
53+
if (message) {
54+
return message;
4755
}
56+
4857
return "(no status code or body)";
4958
}
5059

packages/core/src/v3/errors.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,21 @@ export function taskRunErrorEnhancer(error: TaskRunError): EnhanceError<TaskRunE
690690
};
691691
}
692692

693+
if (error.name === "TriggerApiError") {
694+
if (error.message.startsWith("Deadlock detected:")) {
695+
return {
696+
type: "BUILT_IN_ERROR",
697+
name: "Concurrency Deadlock Error",
698+
message: error.message,
699+
stackTrace: "",
700+
link: {
701+
name: "Read the docs",
702+
href: links.docs.concurrency.deadlock,
703+
},
704+
};
705+
}
706+
}
707+
693708
break;
694709
}
695710
case "STRING_ERROR": {

packages/core/src/v3/links.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const links = {
1818
concurrency: {
1919
recursiveDeadlock:
2020
"https://trigger.dev/docs/queue-concurrency#waiting-for-a-subtask-on-the-same-queue",
21+
deadlock: "https://trigger.dev/docs/queue-concurrency#deadlock",
2122
},
2223
},
2324
site: {

references/hello-world/src/trigger/deadlocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { task, queue } from "@trigger.dev/sdk";
33
const deadlockQueue = queue({
44
name: "deadlock-queue",
55
concurrencyLimit: 1,
6-
releaseConcurrencyOnWaitpoint: true,
6+
releaseConcurrencyOnWaitpoint: false,
77
});
88

99
export const deadlockTester = task({

0 commit comments

Comments
 (0)