From d9d7fe61956da05de88c079acebfa1ef4d084221 Mon Sep 17 00:00:00 2001 From: Freepilot <215356755+freepilot-bot@users.noreply.github.com> Date: Tue, 17 Jun 2025 21:07:52 +0700 Subject: [PATCH] [Freepilot] fix: startup error handling (#1413) * fix: handle errors from service.NewService() in startup code Previously, both HTTP and Wails startup code ignored errors from service.NewService(ctx) using blank identifier (_), which could cause panics later if NewService fails (e.g., unable to connect to postgres database). Now properly handle the error and exit gracefully with a fatal log message when service initialization fails. * fix: compile error --------- Co-authored-by: Roland Bewick --- cmd/http/main.go | 8 ++++++-- main_wails.go | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/http/main.go b/cmd/http/main.go index a833e872..d8fbb94f 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -25,7 +25,11 @@ func main() { signal.Notify(osSignalChannel, os.Interrupt, syscall.SIGTERM) ctx, cancel := context.WithCancel(context.Background()) - svc, _ := service.NewService(ctx) + svc, err := service.NewService(ctx) + if err != nil { + log.WithError(err).Fatal("Failed to create service") + return + } e := echo.New() @@ -54,7 +58,7 @@ func main() { logger.Logger.Info("Shutting down echo server...") ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - err := e.Shutdown(ctx) + err = e.Shutdown(ctx) if err != nil { logger.Logger.WithError(err).Error("Failed to shutdown echo server") } diff --git a/main_wails.go b/main_wails.go index ac47241a..c2c6a5f3 100644 --- a/main_wails.go +++ b/main_wails.go @@ -31,7 +31,11 @@ func main() { log.Info("Alby Hub starting in WAILS mode") ctx, cancel := context.WithCancel(context.Background()) - svc, _ := service.NewService(ctx) + svc, err := service.NewService(ctx) + if err != nil { + log.WithError(err).Fatal("Failed to create service") + return + } app := wails.NewApp(svc) wails.LaunchWailsApp(app, assets, appIcon)