|
1 |
| -import { RunDuplicateIdempotencyKeyError, RunEngine } from "@internal/run-engine"; |
| 1 | +import { |
| 2 | + RunDuplicateIdempotencyKeyError, |
| 3 | + RunEngine, |
| 4 | + RunOneTimeUseTokenError, |
| 5 | +} from "@internal/run-engine"; |
2 | 6 | import { Tracer } from "@opentelemetry/api";
|
| 7 | +import { tryCatch } from "@trigger.dev/core/utils"; |
3 | 8 | import {
|
4 | 9 | TaskRunError,
|
5 | 10 | taskRunErrorEnhancer,
|
6 | 11 | taskRunErrorToString,
|
7 | 12 | TriggerTaskRequestBody,
|
8 | 13 | } from "@trigger.dev/core/v3";
|
9 | 14 | import { RunId, stringifyDuration } from "@trigger.dev/core/v3/isomorphic";
|
10 |
| -import { Prisma, PrismaClientOrTransaction } from "@trigger.dev/database"; |
| 15 | +import { PrismaClientOrTransaction } from "@trigger.dev/database"; |
11 | 16 | import { createTags } from "~/models/taskRunTag.server";
|
12 | 17 | import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
|
13 | 18 | import { logger } from "~/services/logger.server";
|
@@ -122,7 +127,11 @@ export class RunEngineTriggerTaskService {
|
122 | 127 | throw entitlementValidation.error;
|
123 | 128 | }
|
124 | 129 |
|
125 |
| - const delayUntil = await parseDelay(body.options?.delay); |
| 130 | + const [parseDelayError, delayUntil] = await tryCatch(parseDelay(body.options?.delay)); |
| 131 | + |
| 132 | + if (parseDelayError) { |
| 133 | + throw new EngineServiceValidationError(`Invalid delay ${body.options?.delay}`); |
| 134 | + } |
126 | 135 |
|
127 | 136 | const ttl =
|
128 | 137 | typeof body.options?.ttl === "number"
|
@@ -324,32 +333,10 @@ export class RunEngineTriggerTaskService {
|
324 | 333 | return await this.call({ taskId, environment, body, options, attempt: attempt + 1 });
|
325 | 334 | }
|
326 | 335 |
|
327 |
| - // Detect a prisma transaction Unique constraint violation |
328 |
| - if (error instanceof Prisma.PrismaClientKnownRequestError) { |
329 |
| - logger.debug("TriggerTask: Prisma transaction error", { |
330 |
| - code: error.code, |
331 |
| - message: error.message, |
332 |
| - meta: error.meta, |
333 |
| - }); |
334 |
| - |
335 |
| - if (error.code === "P2002") { |
336 |
| - const target = error.meta?.target; |
337 |
| - |
338 |
| - if ( |
339 |
| - Array.isArray(target) && |
340 |
| - target.length > 0 && |
341 |
| - typeof target[0] === "string" && |
342 |
| - target[0].includes("oneTimeUseToken") |
343 |
| - ) { |
344 |
| - throw new EngineServiceValidationError( |
345 |
| - `Cannot trigger ${taskId} with a one-time use token as it has already been used.` |
346 |
| - ); |
347 |
| - } else { |
348 |
| - throw new EngineServiceValidationError( |
349 |
| - `Cannot trigger ${taskId} as it has already been triggered with the same idempotency key.` |
350 |
| - ); |
351 |
| - } |
352 |
| - } |
| 336 | + if (error instanceof RunOneTimeUseTokenError) { |
| 337 | + throw new EngineServiceValidationError( |
| 338 | + `Cannot trigger ${taskId} with a one-time use token as it has already been used.` |
| 339 | + ); |
353 | 340 | }
|
354 | 341 |
|
355 | 342 | throw error;
|
|
0 commit comments