@@ -267,20 +267,28 @@ function startCliServer() {
267267
268268/**
269269 * Start the actual CLI server process
270- * @returns {Promise<BunSubprocess | null> }
270+ * @returns {Promise<BunSubprocess | null> } Returns the subprocess on success, null if spawn fails
271271 */
272272function startActualCliServer ( ) {
273273 return new Promise ( ( resolve ) => {
274274 log ( 'CLI' , 'Starting CLI server process...' ) ;
275275
276- const child = Bun . spawn ( [ 'bun' , 'dist/index.js' , 'start' ] , {
277- cwd : cliDir ,
278- stdio : [ 'inherit' , 'inherit' , 'inherit' ] ,
279- env : {
280- ...process . env ,
281- NODE_ENV : 'development' ,
282- } ,
283- } ) ;
276+ /** @type {BunSubprocess } */
277+ let child ;
278+ try {
279+ child = Bun . spawn ( [ 'bun' , 'dist/index.js' , 'start' ] , {
280+ cwd : cliDir ,
281+ stdio : [ 'inherit' , 'inherit' , 'inherit' ] ,
282+ env : {
283+ ...process . env ,
284+ NODE_ENV : 'development' ,
285+ } ,
286+ } ) ;
287+ } catch ( error ) {
288+ log ( 'CLI' , `Failed to spawn CLI server: ${ error . message } ` ) ;
289+ resolve ( null ) ;
290+ return ;
291+ }
284292
285293 child . exited . then ( ( exitCode ) => {
286294 if ( ! isShuttingDown && ! isRebuilding ) {
@@ -294,7 +302,8 @@ function startActualCliServer() {
294302 if ( ! isShuttingDown && ! isRebuilding ) {
295303 log ( 'CLI' , `CLI server error: ${ error . message } ` ) ;
296304 cleanup ( 'cli-error' ) ;
297- resolve ( null ) ;
305+ // NOTE: We don't resolve(null) here because the Promise is already resolved
306+ // with `child` below. Async errors after process spawn are handled via cleanup().
298307 }
299308 } ) ;
300309
0 commit comments