[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 <roland.bewick@gmail.com>
This commit is contained in:
Freepilot 2025-06-17 21:07:52 +07:00 committed by GitHub
parent 1fab988267
commit d9d7fe6195
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View file

@ -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")
}

View file

@ -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)