Skip to content

Commit 4ccd956

Browse files
committed
fix(run-engine): match classification failures by error name as well as instanceof
The intended thrower of UnclassifiableRunId is an injected classifier, which can arrive from a separately built bundle carrying its own copy of the class, where instanceof misses. The class sets its name explicitly, so the name check keeps the wrap reliable across module instances. A missed match was already harmless (the error bubbled unchanged); this preserves the clearer label in the one scenario the branch exists for.
1 parent 7fa1afc commit 4ccd956

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

internal-packages/run-engine/src/engine/tests/completeWaitpointErrorClassification.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ describe("completeWaitpoint store-resolution error classification", () => {
4949
).rejects.not.toBeInstanceOf(UnclassifiableWaitpointId);
5050
});
5151

52+
it("wraps a classification failure from a foreign module instance (matched by name, not instanceof)", async () => {
53+
const waitpointId = "waitpoint_foreign_instance";
54+
const foreignError = new Error(`Unclassifiable run-ops id: ${waitpointId}`);
55+
foreignError.name = "UnclassifiableRunId";
56+
const waitpointSystem = createWaitpointSystem(() => Promise.reject(foreignError));
57+
58+
const caught = (await waitpointSystem
59+
.completeWaitpoint({ id: waitpointId })
60+
.catch((error: unknown) => error)) as UnclassifiableWaitpointId;
61+
expect(caught).toBeInstanceOf(UnclassifiableWaitpointId);
62+
expect(caught.waitpointId).toBe(waitpointId);
63+
expect(caught.cause).toBe(foreignError);
64+
});
65+
5266
it("wraps a genuine UnclassifiableRunId as UnclassifiableWaitpointId with the original as cause", async () => {
5367
const waitpointId = "waitpoint_unclassifiable";
5468
const classificationError = new UnclassifiableRunId(waitpointId);

internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export class LegacyPostgresWaitpointCoordinator implements WaitpointCoordinator
127127
// database/infra error (e.g. can't reach the database) can surface here too. Those MUST
128128
// bubble up unchanged so they keep their original type, retryability, and error grouping
129129
// instead of being mislabelled as an unclassifiable id.
130-
if (error instanceof UnclassifiableRunId) {
130+
const isClassificationFailure =
131+
error instanceof UnclassifiableRunId ||
132+
(error instanceof Error && error.name === "UnclassifiableRunId");
133+
134+
if (isClassificationFailure) {
131135
this.logger.error("completeWaitpoint: unclassifiable waitpointId", {
132136
waitpointId,
133137
error,

0 commit comments

Comments
 (0)