@@ -13,9 +13,6 @@ import { UnhandledRejectionError } from '../errors';
13
13
import { Workflow } from './interface' ;
14
14
import { WorkflowBundleWithSourceMapAndFilename } from './workflow-worker-thread/input' ;
15
15
16
- // Not present in @types /node for some reason
17
- const { promiseHooks } = v8 as any ;
18
-
19
16
// Best effort to catch unhandled rejections from workflow code.
20
17
// We crash the thread if we cannot find the culprit.
21
18
export function setUnhandledRejectionHandler ( getWorkflowByRunId : ( runId : string ) => BaseVMWorkflow | undefined ) : void {
@@ -106,9 +103,7 @@ export class GlobalHandlers {
106
103
currentStackTrace : StackTraceFileLocation [ ] | undefined = undefined ;
107
104
bundleFilenameToSourceMapConsumer = new Map < string , SourceMapConsumer > ( ) ;
108
105
origPrepareStackTrace = Error . prepareStackTrace ;
109
- private stopPromiseHook = ( ) => {
110
- // noop
111
- } ;
106
+ private stopPromiseHook = ( ) => { } ;
112
107
installed = false ;
113
108
114
109
async addWorkflowBundle ( workflowBundle : WorkflowBundleWithSourceMapAndFilename ) : Promise < void > {
@@ -200,9 +195,8 @@ export class GlobalHandlers {
200
195
let currentAggregation : Promise < unknown > | undefined = undefined ;
201
196
202
197
// This also is set globally for the isolate (worker thread), which is insignificant unless the worker is run in debug mode
203
- if ( promiseHooks ) {
204
- // Node >=16.14 only
205
- this . stopPromiseHook = promiseHooks . createHook ( {
198
+ try {
199
+ this . stopPromiseHook = v8 . promiseHooks . createHook ( {
206
200
init : ( promise : Promise < unknown > , parent : Promise < unknown > ) => {
207
201
// Only run in workflow context
208
202
const activator = getActivator ( promise ) ;
@@ -265,7 +259,13 @@ export class GlobalHandlers {
265
259
store . childToParent . delete ( promise ) ;
266
260
store . promiseToStack . delete ( promise ) ;
267
261
} ,
268
- } ) ;
262
+ } ) as ( ) => void ;
263
+ } catch ( _ ) {
264
+ // v8.promiseHooks.createHook is not available in bun and Node.js < 16.14.0.
265
+ // That's ok, collecting stack trace is an optional feature anyway.
266
+ //
267
+ // FIXME: This should be sent to logs, not the console… but we don't have access to it here.
268
+ console . warn ( 'v8.promiseHooks.createHook is not available; stack trace collection will be disabled.' ) ;
269
269
}
270
270
}
271
271
}
0 commit comments