@@ -16,6 +16,11 @@ import {
1616 type WarmRequest ,
1717} from "./warmCheckProtocol.js" ;
1818
19+ import { appendFileSync as __dbgAppend } from "node:fs" ;
20+ const __dbg = ( m : string ) => __dbgAppend ( process . env . HF_WARM_DBG ?? "warm-dbg.log" , `${ Date . now ( ) } ${ process . pid } ${ m } \n` ) ;
21+ process . on ( "uncaughtException" , ( e ) => __dbg ( `uncaught ${ e ?. stack ?? e } ` ) ) ;
22+ process . on ( "unhandledRejection" , ( e ) => __dbg ( `unhandled ${ ( e as Error ) ?. stack ?? e } ` ) ) ;
23+ __dbg ( `start argv=${ JSON . stringify ( process . argv ) } ` ) ;
1924const [ idleMs = "0" , ...checkArgs ] = process . argv . slice ( 2 ) ;
2025const endpoint = warmCheckEndpoint ( ) ;
2126if ( ! endpoint ) process . exit ( 0 ) ;
@@ -42,6 +47,7 @@ async function serve(socket: Socket, request: WarmRequest): Promise<void> {
4247 const finish = ( code : number ) => {
4348 if ( finished ) return ;
4449 finished = true ;
50+ __dbg ( `finish ${ code } ${ new Error ( ) . stack } ` ) ;
4551 socket . end ( encodeFrame ( Frame . Exit , String ( code ) ) , ( ) => exit ( code ) ) ;
4652 } ;
4753 socket . on ( "close" , ( ) => {
@@ -53,7 +59,9 @@ async function serve(socket: Socket, request: WarmRequest): Promise<void> {
5359 finish ( Number ( code ?? process . exitCode ?? 0 ) ) ) as typeof process . exit ;
5460 process . chdir ( request . cwd ) ;
5561 process . argv = [ process . execPath , request . script , ...request . argv ] ;
62+ __dbg ( `serving ${ JSON . stringify ( request . argv ) } ` ) ;
5663 await import ( new URL ( "./cli.js" , import . meta. url ) . href ) ;
64+ __dbg ( `imported exitCode=${ process . exitCode } ` ) ;
5765 setImmediate ( ( ) => finish ( Number ( process . exitCode ?? 0 ) ) ) ;
5866}
5967
@@ -132,4 +140,4 @@ server.on("error", (error: NodeJS.ErrnoException) => {
132140} ) ;
133141
134142listen ( ) ;
135- void prelaunchBrowserForCheck ( checkArgs ) . catch ( ( ) => undefined ) ;
143+ void prelaunchBrowserForCheck ( checkArgs ) . then ( ( ) => __dbg ( 'prelaunched' ) , ( e ) => __dbg ( `prelaunch failed ${ e ?. stack ?? e } ` ) ) ;
0 commit comments