diff --git a/apps/studio/src/ipc-handlers.ts b/apps/studio/src/ipc-handlers.ts index 6faebbcac3..15622c9469 100644 --- a/apps/studio/src/ipc-handlers.ts +++ b/apps/studio/src/ipc-handlers.ts @@ -616,9 +616,10 @@ export async function updateSite( } export async function startServer( event: IpcMainInvokeEvent, id: string ): Promise< void > { - const site = await getSite( id ); + // Starting only needs the path, which `cli.json` has; the CLI's full details wait for a failure. + const site = await readSite( id ); if ( ! site ) { - return; + throw new Error( `Site not found: ${ id }` ); } // Release the port held by any active PHP-error recovery before (re)starting the real server, @@ -635,10 +636,12 @@ export async function startServer( event: IpcMainInvokeEvent, id: string ): Prom throw error; } + const details = await getSite( id ).catch( () => undefined ); + // A fatal error in the user's own PHP (theme/plugin) code stops WordPress from booting. // Rather than failing the start, serve the parsed PHP error on the site's port and watch for // the fix so the site self-recovers. This is user code, not a Studio bug, so skip Sentry. - if ( isPhpUserError( error ) ) { + if ( details && isPhpUserError( error ) ) { const processManagerLogs = readProcessManagerLogs( id ); const logContent = [ ...( processManagerLogs.stdout ?? [] ), @@ -647,19 +650,19 @@ export async function startServer( event: IpcMainInvokeEvent, id: string ): Prom const errorMessage = parsePhpError( logContent ); try { - await startErrorRecovery( site, errorMessage, readProcessManagerLogs, start ); - console.log( `[PHP Recovery - ${ id }] Serving PHP error page on port ${ site.port }` ); - const url = `http://localhost:${ site.port }`; + await startErrorRecovery( details, errorMessage, readProcessManagerLogs, start ); + console.log( `[PHP Recovery - ${ id }] Serving PHP error page on port ${ details.port }` ); + const url = `http://localhost:${ details.port }`; void sendIpcEventToRenderer( 'site-event', { event: SITE_EVENTS.UPDATED, siteId: id, site: { id, - name: site.name, - path: site.path, - port: site.port, + name: details.name, + path: details.path, + port: details.port, url, - phpVersion: site.phpVersion, + phpVersion: details.phpVersion, }, running: true, } ); @@ -674,11 +677,11 @@ export async function startServer( event: IpcMainInvokeEvent, id: string ): Prom const contexts: Record< string, Record< string, unknown > > = { server: { - running: site.running, - phpVersion: site.phpVersion, - port: site.port, - hasCustomDomain: !! site.customDomain, - httpsEnabled: !! site.enableHttps, + running: details?.running, + phpVersion: details?.phpVersion, + port: details?.port, + hasCustomDomain: !! details?.customDomain, + httpsEnabled: !! details?.enableHttps, }, };