Skip to content

Commit 8f1619b

Browse files
committed
Better batch friendly ID parsing errors
1 parent 02eec34 commit 8f1619b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

apps/webapp/app/runEngine/services/streamBatchItems.server.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ export class StreamBatchItemsService extends WithRunEngine {
4141
this.payloadProcessor = new BatchPayloadProcessor();
4242
}
4343

44+
/**
45+
* Parse a batch friendly ID to its internal ID format.
46+
* Throws a ServiceValidationError with 400 status if the ID is malformed.
47+
*/
48+
private parseBatchFriendlyId(friendlyId: string): string {
49+
try {
50+
return BatchId.fromFriendlyId(friendlyId);
51+
} catch {
52+
throw new ServiceValidationError(`Invalid batchFriendlyId: ${friendlyId}`, 400);
53+
}
54+
}
55+
4456
/**
4557
* Process a stream of batch items from an async iterator.
4658
* Each item is validated and enqueued to the BatchQueue.
@@ -59,7 +71,7 @@ export class StreamBatchItemsService extends WithRunEngine {
5971
span.setAttribute("batchId", batchFriendlyId);
6072

6173
// Convert friendly ID to internal ID
62-
const batchId = BatchId.fromFriendlyId(batchFriendlyId);
74+
const batchId = this.parseBatchFriendlyId(batchFriendlyId);
6375

6476
// Validate batch exists and belongs to this environment
6577
const batch = await this._prisma.batchTaskRun.findFirst({

0 commit comments

Comments
 (0)