Skip to content

Commit d54476f

Browse files
authored
feat(client): Use runId only in handles created with getHandle (#468)
In addition: - Adds safety to `terminate` and `cancel` so handles created with `start` can't accidentally affect workflows that are not part of the same execution chain - Adds optional `firstExecutionRunId` param to `getHandle` for added safety - Closes #464 - Closes #377 - Closes #365
1 parent 67526d3 commit d54476f

File tree

9 files changed

+373
-109
lines changed

9 files changed

+373
-109
lines changed

packages/client/src/async-completion-client.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os from 'os';
2-
import { ServerErrorResponse } from '@grpc/grpc-js';
32
import { Status } from '@grpc/grpc-js/build/src/constants';
43
import {
54
DataConverter,
@@ -9,6 +8,7 @@ import {
98
filterNullAndUndefined,
109
} from '@temporalio/common';
1110
import { Connection, WorkflowService } from './connection';
11+
import { isServerErrorResponse } from './errors';
1212

1313
/**
1414
* Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
@@ -34,14 +34,6 @@ export class ActivityCancelledError extends Error {
3434
public readonly name = 'ActivityCancelledError';
3535
}
3636

37-
/**
38-
* Type assertion helper, assertion is mostly empty because any additional
39-
* properties are optional.
40-
*/
41-
function isServerErrorResponse(err: unknown): err is ServerErrorResponse {
42-
return err instanceof Error;
43-
}
44-
4537
/**
4638
* Options used to configure {@link AsyncCompletionClient}
4739
*/

packages/client/src/errors.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1+
import { ServerErrorResponse } from '@grpc/grpc-js';
12
import { RetryState, TemporalFailure } from '@temporalio/common';
3+
export { WorkflowExecutionAlreadyStartedError } from '@temporalio/common';
4+
5+
/**
6+
* Generic Error class for errors coming from the service
7+
*/
8+
export class ServiceError extends Error {
9+
public readonly name: string = 'ServiceError';
10+
public readonly cause?: Error;
11+
12+
constructor(message: string, opts?: { cause: Error }) {
13+
super(message);
14+
this.cause = opts?.cause;
15+
}
16+
}
217

318
/**
419
* Thrown by the client while waiting on Workflow execution result if execution
@@ -32,3 +47,11 @@ export class WorkflowContinuedAsNewError extends Error {
3247
super(message);
3348
}
3449
}
50+
51+
/**
52+
* Type assertion helper, assertion is mostly empty because any additional
53+
* properties are optional.
54+
*/
55+
export function isServerErrorResponse(err: unknown): err is ServerErrorResponse {
56+
return err instanceof Error;
57+
}

packages/client/src/interceptors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ export interface WorkflowTerminateInput {
4848
readonly workflowExecution: WorkflowExecution;
4949
readonly reason?: string;
5050
readonly details?: unknown[];
51+
readonly firstExecutionRunId?: string;
5152
}
5253

5354
/** Input for WorkflowClientCallsInterceptor.cancel */
5455
export interface WorkflowCancelInput {
5556
readonly workflowExecution: WorkflowExecution;
57+
readonly firstExecutionRunId?: string;
5658
}
5759

5860
/**

packages/client/src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { temporal } from '@temporalio/proto';
22

3-
export type WorkflowExecution = temporal.api.common.v1.IWorkflowExecution;
3+
export interface WorkflowExecution {
4+
workflowId: string;
5+
runId?: string;
6+
}
47
export type StartWorkflowExecutionRequest = temporal.api.workflowservice.v1.IStartWorkflowExecutionRequest;
58
export type GetWorkflowExecutionHistoryRequest = temporal.api.workflowservice.v1.IGetWorkflowExecutionHistoryRequest;
69
export type DescribeWorkflowExecutionResponse = temporal.api.workflowservice.v1.IDescribeWorkflowExecutionResponse;

0 commit comments

Comments
 (0)