Skip to content

Commit

Permalink
improve error messages and use fatal were possible
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten committed Nov 1, 2023
1 parent a2561c5 commit a570a1d
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func run(c *cli.Context) error {

_forge, err := setupForge(c)
if err != nil {
log.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("can't setup forge")
}

_store, err := setupStore(c)
if err != nil {
log.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("cant't setup database store")
}
defer func() {
if err := _store.Close(); err != nil {
Expand All @@ -111,8 +111,7 @@ func run(c *cli.Context) error {
g.Go(func() error {
lis, err := net.Listen("tcp", c.String("grpc-addr"))
if err != nil {
log.Error().Err(err).Msg("failed to listen on grpc-addr")
return err
log.Fatal().Err(err).Msg("failed to listen on grpc-addr")
}

jwtSecret := c.String("grpc-secret")
Expand Down Expand Up @@ -145,8 +144,7 @@ func run(c *cli.Context) error {

err = grpcServer.Serve(lis)
if err != nil {
log.Error().Err(err).Msg("failed to serve grpc server")
return err
log.Fatal().Err(err).Msg("failed to serve grpc server")
}
return nil
})
Expand All @@ -157,8 +155,7 @@ func run(c *cli.Context) error {
if proxyWebUI == "" {
webEngine, err := web.New()
if err != nil {
log.Error().Err(err).Msg("failed to create web engine")
return err
log.Fatal().Err(err).Msg("failed to create web engine")
}
webUIServe = webEngine.ServeHTTP
} else {
Expand Down Expand Up @@ -198,8 +195,8 @@ func run(c *cli.Context) error {
c.String("server-cert"),
c.String("server-key"),
)
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("")
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("failed to start server with tls")
}
return err
})
Expand All @@ -217,8 +214,8 @@ func run(c *cli.Context) error {

g.Go(func() error {
err := http.ListenAndServe(server.Config.Server.Port, http.HandlerFunc(redirect))
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("Not able to start server to redirect from http to https")
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("unable to start server to redirect from http to https")
}
return err
})
Expand All @@ -245,8 +242,8 @@ func run(c *cli.Context) error {
c.String("server-addr"),
handler,
)
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("Can't start server")
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("could not start server")
}
return err
})
Expand All @@ -257,8 +254,8 @@ func run(c *cli.Context) error {
metricsRouter := gin.New()
metricsRouter.GET("/metrics", gin.WrapH(promhttp.Handler()))
err := http.ListenAndServe(metricsServerAddr, metricsRouter)
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("Can't start metrics server")
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal().Err(err).Msg("could not start metrics server")
}
return err
})
Expand Down

0 comments on commit a570a1d

Please sign in to comment.