From ab1930a676f430bdf33d8a56b5b4e7bf5822e8ba Mon Sep 17 00:00:00 2001 From: Pascal Bleser Date: Wed, 4 Feb 2026 11:57:27 +0100 Subject: [PATCH] auth-api: deal with errors properly in NewService --- services/auth-api/pkg/server/http/server.go | 5 ++++- services/auth-api/pkg/service/http/v0/service.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/services/auth-api/pkg/server/http/server.go b/services/auth-api/pkg/server/http/server.go index 33141d1fd8..42f3d56dc2 100644 --- a/services/auth-api/pkg/server/http/server.go +++ b/services/auth-api/pkg/server/http/server.go @@ -32,7 +32,7 @@ func Server(opts ...Option) (http.Service, error) { return http.Service{}, fmt.Errorf("could not initialize http service: %w", err) } - handle := svc.NewService( + handle, err := svc.NewService( svc.Logger(options.Logger), svc.Config(options.Config), svc.Metrics(options.Metrics), @@ -47,6 +47,9 @@ func Server(opts ...Option) (http.Service, error) { opencloudmiddleware.Logger(options.Logger), ), ) + if err != nil { + return http.Service{}, err + } { handle = svc.NewInstrument(handle, options.Metrics) diff --git a/services/auth-api/pkg/service/http/v0/service.go b/services/auth-api/pkg/service/http/v0/service.go index f25e74bc99..0364182e30 100644 --- a/services/auth-api/pkg/service/http/v0/service.go +++ b/services/auth-api/pkg/service/http/v0/service.go @@ -29,7 +29,7 @@ type Service interface { } // NewService returns a service implementation for Service. -func NewService(opts ...Option) Service { +func NewService(opts ...Option) (Service, error) { options := newOptions(opts...) m := chi.NewMux() @@ -47,7 +47,7 @@ func NewService(opts ...Option) Service { svc, err := NewAuthenticationApi(options.Config, &options.Logger, options.Metrics, options.TraceProvider, m) if err != nil { - panic(err) // TODO p.bleser what to do when we encounter an error in a NewService() ? + return nil, err } m.Route(options.Config.HTTP.Root, func(r chi.Router) { @@ -59,7 +59,7 @@ func NewService(opts ...Option) Service { return nil }) - return svc + return svc, nil } type AuthenticationApi struct {