mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
[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:
parent
1fab988267
commit
d9d7fe6195
2 changed files with 11 additions and 3 deletions
|
|
@ -25,7 +25,11 @@ func main() {
|
||||||
signal.Notify(osSignalChannel, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(osSignalChannel, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
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()
|
e := echo.New()
|
||||||
|
|
||||||
|
|
@ -54,7 +58,7 @@ func main() {
|
||||||
logger.Logger.Info("Shutting down echo server...")
|
logger.Logger.Info("Shutting down echo server...")
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
err := e.Shutdown(ctx)
|
err = e.Shutdown(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.WithError(err).Error("Failed to shutdown echo server")
|
logger.Logger.WithError(err).Error("Failed to shutdown echo server")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,11 @@ func main() {
|
||||||
|
|
||||||
log.Info("Alby Hub starting in WAILS mode")
|
log.Info("Alby Hub starting in WAILS mode")
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
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)
|
app := wails.NewApp(svc)
|
||||||
wails.LaunchWailsApp(app, assets, appIcon)
|
wails.LaunchWailsApp(app, assets, appIcon)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue