-
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
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,31 @@ | ||
export const TEMPORAL_RESERVED_PREFIX = '__temporal_'; | ||
export const STACK_TRACE_RESERVED_PREFIX = '__stack_trace'; | ||
export const ENHANCED_STACK_TRACE_RESERVED_PREFIX = '__enhanced_stack_trace'; | ||
|
||
export const reservedPrefixes = [ | ||
TEMPORAL_RESERVED_PREFIX, | ||
STACK_TRACE_RESERVED_PREFIX, | ||
ENHANCED_STACK_TRACE_RESERVED_PREFIX, | ||
]; | ||
|
||
export class ReservedPrefixError extends Error { | ||
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. Is there a good reason to make a custom error type for this, rather than just throwing a But if we'd want to keep that error class (I don't think so), it should have the |
||
constructor(type: string, name: string, prefix: string) { | ||
super(`Cannot use ${type} name: '${name}', with reserved prefix: '${prefix}'`); | ||
this.name = 'ReservedPrefixError'; | ||
} | ||
} | ||
|
||
export function throwIfReservedName(type: string, name: string): void { | ||
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.
|
||
const prefix = maybeGetReservedPrefix(name); | ||
if (prefix) { | ||
throw new ReservedPrefixError(type, name, prefix); | ||
} | ||
} | ||
|
||
export function maybeGetReservedPrefix(name: string): string | undefined { | ||
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. This check needs to vary based on type; not all reserved name patterns apply to all types. Also, not all reserved name patterns are prefixes; With that in mind, I don't think using a loop makes sense. Also, I have no strong opinion about having the check logic externalized to this file, but it looks that's not what we did in other SDKs. |
||
for (const prefix of reservedPrefixes) { | ||
if (name.startsWith(prefix)) { | ||
return prefix; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { loadDataConverter } from '@temporalio/common/lib/internal-non-workflow' | |
import { LoggerSinks } from '@temporalio/workflow'; | ||
import { Context } from '@temporalio/activity'; | ||
import { native } from '@temporalio/core-bridge'; | ||
import { throwIfReservedName } from '@temporalio/common/lib/reserved'; | ||
import { ActivityInboundLogInterceptor } from './activity-log-interceptor'; | ||
import { NativeConnection } from './connection'; | ||
import { CompiledWorkerInterceptors, WorkerInterceptors } from './interceptors'; | ||
|
@@ -953,6 +954,9 @@ export function compileWorkerOptions( | |
} | ||
|
||
const activities = new Map(Object.entries(opts.activities ?? {}).filter(([_, v]) => typeof v === 'function')); | ||
for (const activityName of activities.keys()) { | ||
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. We also need to check sinks. |
||
throwIfReservedName('activity', activityName); | ||
} | ||
const tuner = asNativeTuner(opts.tuner, logger); | ||
|
||
return { | ||
|
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,7 @@ 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> { | ||
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, |
||
const runtime = Runtime.instance(); | ||
const logger = LoggerWithComposedMetadata.compose(runtime.logger, { | ||
sdkComponent: SdkComponent.worker, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not a prefix. Same for next line.