Skip to content

Fix for v4 run failed alerts missing error #2031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 6 additions & 45 deletions apps/webapp/app/v3/services/alerts/deliverAlert.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { sendAlertEmail } from "~/services/email.server";
import { logger } from "~/services/logger.server";
import { decryptSecret } from "~/services/secrets/secretStore.server";
import { commonWorker } from "~/v3/commonWorker.server";
import { FINAL_ATTEMPT_STATUSES } from "~/v3/taskStatus";
import { BaseService } from "../baseService.server";
import { generateFriendlyId } from "~/v3/friendlyIdentifiers";
import { type ProjectAlertChannelType, type ProjectAlertType } from "@trigger.dev/database";
Expand All @@ -53,13 +52,6 @@ type FoundAlert = Prisma.Result<
};
};
environment: true;
taskRunAttempt: {
include: {
taskRun: true;
backgroundWorkerTask: true;
backgroundWorker: true;
};
};
taskRun: {
include: {
lockedBy: true;
Expand All @@ -78,13 +70,7 @@ type FoundAlert = Prisma.Result<
};
},
"findUniqueOrThrow"
> & {
failedAttempt?: Prisma.Result<
typeof prisma.taskRunAttempt,
{ select: { output: true; outputType: true; error: true } },
"findFirst"
>;
};
>;

class SkipRetryError extends Error {}

Expand All @@ -100,13 +86,6 @@ export class DeliverAlertService extends BaseService {
},
},
environment: true,
taskRunAttempt: {
include: {
taskRun: true,
backgroundWorkerTask: true,
backgroundWorker: true,
},
},
taskRun: {
include: {
lockedBy: true,
Expand All @@ -133,24 +112,6 @@ export class DeliverAlertService extends BaseService {
return;
}

if (alert.taskRun) {
const finishedAttempt = await this._prisma.taskRunAttempt.findFirst({
select: {
output: true,
outputType: true,
error: true,
},
where: {
status: { in: FINAL_ATTEMPT_STATUSES },
taskRunId: alert.taskRun.id,
},
orderBy: {
createdAt: "desc",
},
});
alert.failedAttempt = finishedAttempt;
}

try {
switch (alert.channel.type) {
case "EMAIL": {
Expand Down Expand Up @@ -1014,18 +975,18 @@ export class DeliverAlertService extends BaseService {
}

#getRunError(alert: FoundAlert): TaskRunError {
if (alert.failedAttempt) {
const res = TaskRunError.safeParse(alert.failedAttempt.error);
if (alert.taskRun) {
const res = TaskRunError.safeParse(alert.taskRun.error);

if (!res.success) {
logger.error("[DeliverAlert] Failed to parse task run error, sending with unknown error", {
issues: res.error.issues,
taskAttemptError: alert.failedAttempt.error,
taskRunError: alert.taskRun.error,
});

return {
type: "CUSTOM_ERROR",
raw: JSON.stringify(alert.failedAttempt.error ?? "Unknown error"),
raw: JSON.stringify(alert.taskRun.error ?? "Unknown error"),
};
}

Expand All @@ -1034,7 +995,7 @@ export class DeliverAlertService extends BaseService {

return {
type: "CUSTOM_ERROR",
raw: "No error on attempt",
raw: "No error on run",
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { type Prisma, type ProjectAlertChannel } from "@trigger.dev/database";
import { $transaction, type PrismaClientOrTransaction, type prisma } from "~/db.server";
import { workerQueue } from "~/services/worker.server";
import { generateFriendlyId } from "~/v3/friendlyIdentifiers";
import { type prisma } from "~/db.server";
import { commonWorker } from "~/v3/commonWorker.server";
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

import { type prisma } … breaks typeof prisma – import the value, not just the type

FoundRun relies on typeof prisma.taskRun, which is a value query.
When prisma is imported with the type modifier, the symbol only exists in the
type-space; the value symbol is erased, so typeof prisma triggers TS 2749
(“only refers to a type, but is being used as a value here”).

-import { type prisma } from "~/db.server";
+import { prisma } from "~/db.server";

If you still want to avoid bringing the runtime value into the bundle, replace
typeof prisma.taskRun with the model–name type from @prisma/client instead
(e.g. Prisma.TaskRunDelegate).
Failing to adjust this will cause the file not to compile.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { type prisma } from "~/db.server";
import { commonWorker } from "~/v3/commonWorker.server";
import { prisma } from "~/db.server";
import { commonWorker } from "~/v3/commonWorker.server";

import { BaseService } from "../baseService.server";
import { DeliverAlertService } from "./deliverAlert.server";
import { commonWorker } from "~/v3/commonWorker.server";

type FoundRun = Prisma.Result<
typeof prisma.taskRun,
Expand Down