@@ -11,27 +11,29 @@ if (process.platform == 'linux') {
1111 const { AsyncLocalStorage } = require ( 'node:async_hooks' ) ;
1212 let als = undefined ;
1313
14- function hasAsyncContextFrame ( ) {
14+ function asyncContextFrameError ( ) {
1515 const [ major ] = process . versions . node . split ( '.' ) . map ( Number ) ;
1616
1717 // If explicitly disabled, it's not in use.
18- if ( process . execArgv . includes ( '--no-async-context-frame' ) ) return false ;
18+ if ( process . execArgv . includes ( '--no-async-context-frame' ) ) return "Node explicitly launched with --no-async-context-frame" ;
1919
2020 // Since Node 24, AsyncContextFrame is the default unless disabled.
21- if ( major >= 24 ) return true ;
21+ if ( major >= 24 ) return undefined ;
2222
2323 // In Node 22/23, it existed behind an experimental flag.
24- if ( process . execArgv . includes ( '--experimental-async-context-frame' ) ) return true ;
24+ if ( process . execArgv . includes ( '--experimental-async-context-frame' ) ) return undefined ;
25+ if ( major >= 22 ) return "Node versions prior to v24 must be launched with --experimental-async-context-frame" ;
2526
2627 // Older versions: not available.
27- return false ;
28+ return "Node major versions prior to v22 do not support the feature at all" ;
2829 }
2930
3031 function ensureHook ( ) {
3132 if ( als )
3233 return ;
33- if ( ! hasAsyncContextFrame ( ) ) {
34- throw new Error ( "This library can only run with async context frame support enabled" ) ;
34+ const err = asyncContextFrameError ( ) ;
35+ if ( err ) {
36+ throw new Error ( `Custom labels requires async_context_frame support, which is unavailable: ${ err } .` ) ;
3537 }
3638 als = new AsyncLocalStorage ( ) ;
3739 addon . storeHash ( als ) ;
0 commit comments