-
Notifications
You must be signed in to change notification settings - Fork 127
Special behaviour for temporal prefixes #1644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3b3a6d5
0d05950
8237158
efe9d69
dfb0244
55c641f
12062bc
73823fa
3a8683a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const TEMPORAL_RESERVED_PREFIX = '__temporal_'; | ||
export const STACK_TRACE_RESERVED_NAME = '__stack_trace'; | ||
export const ENHANCED_STACK_TRACE_RESERVED_NAME = '__enhanced_stack_trace'; | ||
|
||
/** | ||
* Valid entity types that can be checked for reserved name violations | ||
*/ | ||
export type ReservedNameEntityType = 'query' | 'signal' | 'update' | 'activity' | 'task queue' | 'sink' | 'workflow'; | ||
|
||
/** | ||
* Validates if the provided name contains any reserved prefixes or matches any reserved names. | ||
* Throws a TypeError if validation fails, with a specific message indicating whether the issue | ||
* is with a reserved prefix or an exact match to a reserved name. | ||
* | ||
* @param type The entity type being checked | ||
* @param name The name to check against reserved prefixes/names | ||
*/ | ||
export function throwIfReservedName(type: ReservedNameEntityType, name: string): void { | ||
if (name.startsWith(TEMPORAL_RESERVED_PREFIX)) { | ||
throw new TypeError(`Cannot use ${type} name: '${name}', with reserved prefix: '${TEMPORAL_RESERVED_PREFIX}'`); | ||
} | ||
|
||
if (name === STACK_TRACE_RESERVED_NAME || name === ENHANCED_STACK_TRACE_RESERVED_NAME) { | ||
throw new TypeError(`Cannot use ${type} name: '${name}', which is a reserved name`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ import { workflowLogAttributes } from '@temporalio/workflow/lib/logs'; | |
import { native } from '@temporalio/core-bridge'; | ||
import { coresdk, temporal } from '@temporalio/proto'; | ||
import { type SinkCall, type WorkflowInfo } from '@temporalio/workflow'; | ||
import { throwIfReservedName } from '@temporalio/common/lib/reserved'; | ||
import { Activity, CancelReason, activityLogAttributes } from './activity'; | ||
import { extractNativeClient, extractReferenceHolders, InternalNativeConnection, NativeConnection } from './connection'; | ||
import { ActivityExecuteInput } from './interceptors'; | ||
|
@@ -467,6 +468,10 @@ export class Worker { | |
* This method initiates a connection to the server and will throw (asynchronously) on connection failure. | ||
*/ | ||
public static async create(options: WorkerOptions): Promise<Worker> { | ||
if (!options.taskQueue) { | ||
throw new TypeError('Task queue name is required'); | ||
} | ||
throwIfReservedName('task queue', options.taskQueue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a check but the WorkerOptions interface says that taskQueue can only be string |
||
const runtime = Runtime.instance(); | ||
const logger = LoggerWithComposedMetadata.compose(runtime.logger, { | ||
sdkComponent: SdkComponent.worker, | ||
|
Uh oh!
There was an error while loading. Please reload this page.