Skip to content

Commit 0f5a9d3

Browse files
authored
fix(client): Throw WorkflowExecutionAlreadyStartedError on signalWithStart (#1199)
1 parent 543713a commit 0f5a9d3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/client/src/workflow-client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,14 @@ export class WorkflowClient extends BaseClient {
700700
};
701701
try {
702702
return (await this.workflowService.signalWithStartWorkflowExecution(req)).runId;
703-
} catch (err) {
703+
} catch (err: any) {
704+
if (err.code === grpcStatus.ALREADY_EXISTS) {
705+
throw new WorkflowExecutionAlreadyStartedError(
706+
'Workflow execution already started',
707+
options.workflowId,
708+
workflowType
709+
);
710+
}
704711
this.rethrowGrpcError(err, 'Failed to signalWithStart Workflow', { workflowId: options.workflowId });
705712
}
706713
}

packages/test/src/integration-tests.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
TimeoutType,
3131
WorkflowExecution,
3232
WorkflowExecutionAlreadyStartedError,
33+
WorkflowIdReusePolicy,
3334
WorkflowNotFoundError,
3435
} from '@temporalio/common';
3536
import { msToNumber, tsToMs } from '@temporalio/common/lib/time';
@@ -1138,6 +1139,28 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
11381139
}
11391140
});
11401141

1142+
test('WorkflowClient.signalWithStart fails with WorkflowExecutionAlreadyStartedError', async (t) => {
1143+
const { client } = t.context;
1144+
const workflowId = uuid4();
1145+
await client.execute(workflows.sleeper, {
1146+
taskQueue: 'test',
1147+
workflowId,
1148+
});
1149+
await t.throwsAsync(
1150+
client.signalWithStart(workflows.sleeper, {
1151+
taskQueue: 'test',
1152+
workflowId,
1153+
signal: workflows.interruptSignal,
1154+
signalArgs: ['interrupted from signalWithStart'],
1155+
workflowIdReusePolicy: WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE,
1156+
}),
1157+
{
1158+
instanceOf: WorkflowExecutionAlreadyStartedError,
1159+
message: 'Workflow execution already started',
1160+
}
1161+
);
1162+
});
1163+
11411164
test('Handle from WorkflowClient.start follows only own execution chain', async (t) => {
11421165
const { client } = t.context;
11431166
const workflowId = uuid4();

0 commit comments

Comments
 (0)