fix(gateway): log startup errors before exit

This commit is contained in:
afjcjsbx 2026-04-07 17:50:29 +02:00
parent 6ce0306c66
commit e08d1c4975

View file

@ -111,7 +111,7 @@ func (p *startupBlockedProvider) GetDefaultModel() string {
} }
// Run starts the gateway runtime using the configuration loaded from configPath. // Run starts the gateway runtime using the configuration loaded from configPath.
func Run(debug bool, homePath, configPath string, allowEmptyStartup bool) error { func Run(debug bool, homePath, configPath string, allowEmptyStartup bool) (runErr error) {
panicPath := filepath.Join(homePath, logPath, panicFile) panicPath := filepath.Join(homePath, logPath, panicFile)
panicFunc, err := logger.InitPanic(panicPath) panicFunc, err := logger.InitPanic(panicPath)
if err != nil { if err != nil {
@ -129,6 +129,17 @@ func Run(debug bool, homePath, configPath string, allowEmptyStartup bool) error
} else { } else {
logger.SetLevelFromString(config.ResolveGatewayLogLevel(configPath)) logger.SetLevelFromString(config.ResolveGatewayLogLevel(configPath))
} }
defer func() {
if runErr != nil {
logger.ErrorCF("gateway", "Gateway startup failed", map[string]any{
"config_path": configPath,
"error": runErr.Error(),
"home_path": homePath,
"allow_empty": allowEmptyStartup,
"debug": debug,
})
}
}()
cfg, err := config.LoadConfig(configPath) cfg, err := config.LoadConfig(configPath)
if err != nil { if err != nil {