@@ -3,7 +3,7 @@ import path from 'node:path'
33import * as filesystem from 'fs-extra'
44import { app , BrowserWindow , net } from 'electron'
55import { appLoggerInstance } from '../logging/logger.ts'
6- import { ApiService , DeviceService , PythonService , createEnhancedErrorDetails } from './service.ts'
6+ import { ApiService , DeviceService , PythonService , createEnhancedErrorDetails , ErrorDetails } from './service.ts'
77import { promisify } from 'util'
88import { exec } from 'child_process'
99import { detectLevelZeroDevices } from './deviceDetection.ts'
@@ -45,6 +45,9 @@ export class OllamaBackendService implements ApiService {
4545 encapsulatedProcess : ChildProcess | null = null
4646 desiredStatus : BackendStatus = 'uninitializedStatus'
4747
48+ // Store last startup error details for persistence
49+ private lastStartupErrorDetails : ErrorDetails | null = null
50+
4851 // Logger
4952 readonly appLogger = appLoggerInstance
5053
@@ -117,6 +120,7 @@ export class OllamaBackendService implements ApiService {
117120 isSetUp : this . isSetUp ,
118121 isRequired : this . isRequired ,
119122 devices : this . devices ,
123+ errorDetails : this . lastStartupErrorDetails ,
120124 }
121125 }
122126
@@ -220,7 +224,7 @@ export class OllamaBackendService implements ApiService {
220224 this . setStatus ( 'installationFailed' )
221225
222226 // Create detailed error information for any type of error
223- const errorDetails = createEnhancedErrorDetails ( e , `${ currentStep } operation` )
227+ const errorDetails = await createEnhancedErrorDetails ( e , `${ currentStep } operation` , this . aiBackend )
224228
225229 yield {
226230 serviceName : this . name ,
@@ -326,6 +330,8 @@ export class OllamaBackendService implements ApiService {
326330 throw new Error ( 'Server currently stopping. Cannot start it.' )
327331 }
328332 if ( this . currentStatus === 'running' ) {
333+ // Clear error on successful running status
334+ this . clearLastStartupError ( )
329335 return 'running'
330336 }
331337 if ( this . desiredStatus === 'running' ) {
@@ -343,12 +349,23 @@ export class OllamaBackendService implements ApiService {
343349 this . currentStatus = 'running'
344350 this . appLogger . info ( `started server ${ this . name } on ${ this . baseUrl } ` , this . name )
345351 this . isSetUp = true
352+ // Clear error on successful startup
353+ this . clearLastStartupError ( )
346354 } else {
347355 this . currentStatus = 'failed'
348356 this . desiredStatus = 'failed'
349357 this . isSetUp = false
350358 this . appLogger . error ( `server ${ this . name } failed to boot` , this . name )
351359 this . encapsulatedProcess ?. kill ( )
360+
361+ // Capture detailed error information for startup failure
362+ const startupError = new Error ( `Server ${ this . name } failed to boot - health check timeout or early process exit` )
363+ const errorDetails = await createEnhancedErrorDetails (
364+ startupError ,
365+ 'service startup' ,
366+ this . aiBackend
367+ )
368+ this . setLastStartupError ( errorDetails )
352369 }
353370 } catch ( error ) {
354371 this . appLogger . error ( `failed to start server due to ${ error } ` , this . name )
@@ -357,6 +374,14 @@ export class OllamaBackendService implements ApiService {
357374 this . isSetUp = false
358375 this . encapsulatedProcess ?. kill ( )
359376 this . encapsulatedProcess = null
377+
378+ // Capture detailed error information for startup exception
379+ const errorDetails = await createEnhancedErrorDetails (
380+ error ,
381+ 'service startup' ,
382+ this . aiBackend
383+ )
384+ this . setLastStartupError ( errorDetails )
360385 } finally {
361386 this . win . webContents . send ( 'serviceInfoUpdate' , this . get_info ( ) )
362387 }
@@ -382,13 +407,28 @@ export class OllamaBackendService implements ApiService {
382407 return 'stopped'
383408 }
384409
410+ // Error management methods for startup failures
411+ setLastStartupError ( errorDetails : ErrorDetails ) : void {
412+ this . lastStartupErrorDetails = errorDetails
413+ }
414+
415+ getLastStartupError ( ) : ErrorDetails | null {
416+ return this . lastStartupErrorDetails
417+ }
418+
419+ clearLastStartupError ( ) : void {
420+ this . lastStartupErrorDetails = null
421+ }
422+
385423 async uninstall ( ) : Promise < void > {
386424 await this . stop ( )
387425 this . appLogger . info ( `removing Ollama service directory` , this . name )
388426 await filesystem . remove ( this . serviceDir )
389427 this . appLogger . info ( `removed Ollama service directory` , this . name )
390428 this . setStatus ( 'notInstalled' )
391429 this . isSetUp = false
430+ // Clear startup errors when uninstalling
431+ this . clearLastStartupError ( )
392432 }
393433
394434 pipeProcessLogs ( process : ChildProcess ) {
0 commit comments