Skip to content

Commit a6849af

Browse files
authored
Update stack trace interfaces to match new protos (#1454)
1 parent 2de1b01 commit a6849af

File tree

5 files changed

+63
-52
lines changed

5 files changed

+63
-52
lines changed

packages/test/src/integration-tests-old.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,8 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
13431343
const stacks = enhancedStack.stacks.map((s) => ({
13441344
locations: s.locations.map((l) => ({
13451345
...l,
1346-
...(l.filePath
1347-
? { filePath: l.filePath.replace(path.resolve(__dirname, '../../../'), '').replace(/\\/g, '/') }
1346+
...(l.file_path
1347+
? { file_path: l.file_path.replace(path.resolve(__dirname, '../../../'), '').replace(/\\/g, '/') }
13481348
: undefined),
13491349
})),
13501350
}));
@@ -1354,43 +1354,48 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
13541354
{
13551355
locations: [
13561356
{
1357-
functionName: 'Function.all',
1357+
function_name: 'Function.all',
1358+
internal_code: false,
13581359
},
13591360
{
1360-
filePath: '/packages/test/src/workflows/stack-tracer.ts',
1361-
functionName: 'enhancedStackTracer',
1361+
file_path: '/packages/test/src/workflows/stack-tracer.ts',
1362+
function_name: 'enhancedStackTracer',
13621363
line: 32,
13631364
column: 35,
1365+
internal_code: false,
13641366
},
13651367
],
13661368
},
13671369
{
13681370
locations: [
13691371
{
1370-
filePath: '/packages/test/src/workflows/stack-tracer.ts',
1371-
functionName: 'enhancedStackTracer',
1372+
file_path: '/packages/test/src/workflows/stack-tracer.ts',
1373+
function_name: 'enhancedStackTracer',
13721374
line: 32,
13731375
column: 35,
1376+
internal_code: false,
13741377
},
13751378
],
13761379
},
13771380
{
13781381
locations: [
13791382
{
1380-
functionName: 'Promise.then',
1383+
function_name: 'Promise.then',
1384+
internal_code: false,
13811385
},
13821386
{
1383-
filePath: '/packages/workflow/src/trigger.ts',
1384-
functionName: 'Trigger.then',
1387+
file_path: '/packages/workflow/src/trigger.ts',
1388+
function_name: 'Trigger.then',
13851389
line: 47,
13861390
column: 24,
1391+
internal_code: false,
13871392
},
13881393
],
13891394
},
13901395
]);
13911396
const expectedSources = ['../src/workflows/stack-tracer.ts', '../../workflow/src/trigger.ts'].map((p) => [
13921397
path.resolve(__dirname, p),
1393-
[{ content: readFileSync(path.resolve(__dirname, p), 'utf8'), lineOffset: 0 }],
1398+
[{ content: readFileSync(path.resolve(__dirname, p), 'utf8'), line_offset: 0 }],
13941399
]);
13951400
t.deepEqual(Object.entries(enhancedStack.sources), expectedSources);
13961401
});

packages/worker/src/workflow/vm-shared.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import vm from 'node:vm';
33
import { SourceMapConsumer } from 'source-map';
44
import { cutoffStackTrace, IllegalStateError } from '@temporalio/common';
55
import { coresdk } from '@temporalio/proto';
6-
import type { WorkflowInfo, FileLocation } from '@temporalio/workflow';
6+
import type { WorkflowInfo, StackTraceFileLocation } from '@temporalio/workflow';
77
import { type SinkCall } from '@temporalio/workflow/lib/sinks';
88
import * as internals from '@temporalio/workflow/lib/worker-interface';
99
import { Activator } from '@temporalio/workflow/lib/internals';
@@ -36,18 +36,18 @@ export function setUnhandledRejectionHandler(getWorkflowByRunId: (runId: string)
3636
/**
3737
* Variant of {@link cutoffStackTrace} that works with FileLocation, keep this in sync with the original implementation
3838
*/
39-
function cutoffStructuredStackTrace(stackTrace: FileLocation[]): void {
39+
function cutoffStructuredStackTrace(stackTrace: StackTraceFileLocation[]): void {
4040
stackTrace.shift();
41-
if (stackTrace[0].functionName === 'initAll' && stackTrace[0].filePath === 'node:internal/promise_hooks') {
41+
if (stackTrace[0].function_name === 'initAll' && stackTrace[0].file_path === 'node:internal/promise_hooks') {
4242
stackTrace.shift();
4343
}
44-
const idx = stackTrace.findIndex(({ functionName, filePath }) => {
44+
const idx = stackTrace.findIndex(({ function_name, file_path }) => {
4545
return (
46-
functionName &&
47-
filePath &&
48-
((/^Activator\.\S+NextHandler$/.test(functionName) &&
49-
/.*[\\/]workflow[\\/](?:src|lib)[\\/]internals\.[jt]s$/.test(filePath)) ||
50-
(/Script\.runInContext/.test(functionName) && /^node:vm|vm\.js$/.test(filePath)))
46+
function_name &&
47+
file_path &&
48+
((/^Activator\.\S+NextHandler$/.test(function_name) &&
49+
/.*[\\/]workflow[\\/](?:src|lib)[\\/]internals\.[jt]s$/.test(file_path)) ||
50+
(/Script\.runInContext/.test(function_name) && /^node:vm|vm\.js$/.test(file_path)))
5151
);
5252
});
5353
if (idx > -1) {
@@ -98,7 +98,7 @@ export function injectConsole(context: vm.Context): void {
9898
* Global handlers for overriding stack trace preparation and promise hooks
9999
*/
100100
export class GlobalHandlers {
101-
currentStackTrace: FileLocation[] | undefined = undefined;
101+
currentStackTrace: StackTraceFileLocation[] | undefined = undefined;
102102
bundleFilenameToSourceMapConsumer = new Map<string, SourceMapConsumer>();
103103
origPrepareStackTrace = Error.prepareStackTrace;
104104
private stopPromiseHook = () => {
@@ -163,10 +163,11 @@ export class GlobalHandlers {
163163

164164
const name = pos.name || formatCallsiteName(callsite);
165165
this.currentStackTrace?.push({
166-
filePath: pos.source ?? undefined,
167-
functionName: name ?? undefined,
166+
file_path: pos.source ?? undefined,
167+
function_name: name ?? undefined,
168168
line: pos.line ?? undefined,
169169
column: pos.column ?? undefined,
170+
internal_code: false,
170171
});
171172

172173
return name
@@ -176,10 +177,11 @@ export class GlobalHandlers {
176177
const name = formatCallsiteName(callsite);
177178

178179
this.currentStackTrace?.push({
179-
filePath: filename ?? undefined,
180-
functionName: name ?? undefined,
180+
file_path: filename ?? undefined,
181+
function_name: name ?? undefined,
181182
line: line ?? undefined,
182183
column: column ?? undefined,
184+
internal_code: false,
183185
});
184186
return ` at ${callsite}`;
185187
}
@@ -219,7 +221,7 @@ export class GlobalHandlers {
219221
if (this.currentStackTrace === undefined) {
220222
return;
221223
}
222-
const structured = this.currentStackTrace as FileLocation[];
224+
const structured = this.currentStackTrace as StackTraceFileLocation[];
223225
cutoffStructuredStackTrace(structured);
224226
let stackTrace = { formatted, structured };
225227

packages/workflow/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ export {
9292
ContinueAsNew,
9393
ContinueAsNewOptions,
9494
EnhancedStackTrace,
95-
FileLocation,
96-
FileSlice,
95+
StackTraceFileLocation,
96+
StackTraceFileSlice,
9797
ParentClosePolicy,
9898
ParentWorkflowInfo,
99-
SDKInfo,
99+
StackTraceSDKInfo,
100100
StackTrace,
101101
UnsafeWorkflowInfo,
102102
WorkflowInfo,

packages/workflow/src/interfaces.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,34 +382,34 @@ export type RequiredChildWorkflowOptions = Required<Pick<ChildWorkflowOptions, '
382382

383383
export type ChildWorkflowOptionsWithDefaults = ChildWorkflowOptions & RequiredChildWorkflowOptions;
384384

385-
export interface SDKInfo {
385+
export interface StackTraceSDKInfo {
386386
name: string;
387387
version: string;
388388
}
389389

390390
/**
391391
* Represents a slice of a file starting at lineOffset
392392
*/
393-
export interface FileSlice {
393+
export interface StackTraceFileSlice {
394394
/**
395-
* slice of a file with `\n` (newline) line terminator.
395+
* Only used possible to trim the file without breaking syntax highlighting.
396396
*/
397-
content: string;
397+
line_offset: number;
398398
/**
399-
* Only used possible to trim the file without breaking syntax highlighting.
399+
* slice of a file with `\n` (newline) line terminator.
400400
*/
401-
lineOffset: number;
401+
content: string;
402402
}
403403

404404
/**
405405
* A pointer to a location in a file
406406
*/
407-
export interface FileLocation {
407+
export interface StackTraceFileLocation {
408408
/**
409409
* Path to source file (absolute or relative).
410410
* When using a relative path, make sure all paths are relative to the same root.
411411
*/
412-
filePath?: string;
412+
file_path?: string;
413413
/**
414414
* If possible, SDK should send this, required for displaying the code location.
415415
*/
@@ -422,24 +422,28 @@ export interface FileLocation {
422422
* Function name this line belongs to (if applicable).
423423
* Used for falling back to stack trace view.
424424
*/
425-
functionName?: string;
425+
function_name?: string;
426+
/**
427+
* Flag to mark this as internal SDK code and hide by default in the UI.
428+
*/
429+
internal_code: boolean;
426430
}
427431

428432
export interface StackTrace {
429-
locations: FileLocation[];
433+
locations: StackTraceFileLocation[];
430434
}
431435

432436
/**
433437
* Used as the result for the enhanced stack trace query
434438
*/
435439
export interface EnhancedStackTrace {
436-
sdk: SDKInfo;
440+
sdk: StackTraceSDKInfo;
437441
/**
438442
* Mapping of file path to file contents.
439443
* SDK may choose to send no, some or all sources.
440444
* Sources might be trimmed, and some time only the file(s) of the top element of the trace will be sent.
441445
*/
442-
sources: Record<string, FileSlice[]>;
446+
sources: Record<string, StackTraceFileSlice[]>;
443447
stacks: StackTrace[];
444448
}
445449

packages/workflow/src/internals.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import { QueryInput, SignalInput, UpdateInput, WorkflowExecuteInput, WorkflowInt
2727
import {
2828
ContinueAsNew,
2929
DefaultSignalHandler,
30-
SDKInfo,
31-
FileSlice,
30+
StackTraceSDKInfo,
31+
StackTraceFileSlice,
3232
EnhancedStackTrace,
33-
FileLocation,
33+
StackTraceFileLocation,
3434
WorkflowInfo,
3535
WorkflowCreateOptionsInternal,
3636
} from './interfaces';
@@ -49,7 +49,7 @@ checkExtends<StartChildWorkflowExecutionFailedCause, coresdk.child_workflow.Star
4949

5050
export interface Stack {
5151
formatted: string;
52-
structured: FileLocation[];
52+
structured: StackTraceFileLocation[];
5353
}
5454

5555
/**
@@ -176,19 +176,19 @@ export class Activator implements ActivationHandler {
176176
{
177177
handler: (): EnhancedStackTrace => {
178178
const { sourceMap } = this;
179-
const sdk: SDKInfo = { name: 'typescript', version: pkg.version };
179+
const sdk: StackTraceSDKInfo = { name: 'typescript', version: pkg.version };
180180
const stacks = this.getStackTraces().map(({ structured: locations }) => ({ locations }));
181-
const sources: Record<string, FileSlice[]> = {};
181+
const sources: Record<string, StackTraceFileSlice[]> = {};
182182
if (this.showStackTraceSources) {
183183
for (const { locations } of stacks) {
184-
for (const { filePath } of locations) {
185-
if (!filePath) continue;
186-
const content = sourceMap?.sourcesContent?.[sourceMap?.sources.indexOf(filePath)];
184+
for (const { file_path } of locations) {
185+
if (!file_path) continue;
186+
const content = sourceMap?.sourcesContent?.[sourceMap?.sources.indexOf(file_path)];
187187
if (!content) continue;
188-
sources[filePath] = [
188+
sources[file_path] = [
189189
{
190+
line_offset: 0,
190191
content,
191-
lineOffset: 0,
192192
},
193193
];
194194
}

0 commit comments

Comments
 (0)