diff --git a/server/app/app.go b/server/app/app.go index 1517c9fa79..869339f3d0 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -139,11 +139,11 @@ func (app *App) initAnalytics(configFromDB config.Config) error { return analytics.Init(configFromDB.IsAnalyticsEnabled(), app.serverID, version.Version, version.Env, app.cfg.AnalyticsServerKey(), app.cfg.AnalyticsFrontendKey()) } +// instanceID is a temporary ID for this instance of the server +// it is regenerated on every start intentionally var instanceID = id.GenerateID().String() func (app *App) Start(opts ...appOption) error { - // instanceID is a temporary ID for this instance of the server - // it is regenerated on every start intentionally for _, opt := range opts { opt(app) } @@ -153,18 +153,18 @@ func (app *App) Start(opts ...appOption) error { poolcfg, err := pgxpool.ParseConfig(app.cfg.PostgresConnString()) if err != nil { - return err + return fmt.Errorf("could not parse postgres connection string: %w", err) } poolcfg.MaxConns = 20 pool, err := pgxpool.NewWithConfig(context.Background(), poolcfg) if err != nil { - return err + return fmt.Errorf("could not create postgres connection pool: %w", err) } db, err := testdb.Connect(app.cfg.PostgresConnString()) if err != nil { - return err + return fmt.Errorf("could not connect to postgres: %w", err) } db.SetMaxOpenConns(80) @@ -173,7 +173,7 @@ func (app *App) Start(opts ...appOption) error { ) if err != nil { - log.Fatal(err) + log.Fatal(fmt.Errorf("could not create testdb: %w", err)) } natsConn, err := nats.Connect(app.cfg.NATSEndpoint()) @@ -189,12 +189,12 @@ func (app *App) Start(opts ...appOption) error { tracer, err := telemetry.NewTracer(ctx, app.cfg) if err != nil { - log.Fatal(err) + log.Fatal(fmt.Errorf("could not create tracer: %w", err)) } meter, err := telemetry.NewMeter(ctx, app.cfg) if err != nil { - log.Fatal(err) + log.Fatal(fmt.Errorf("could not create meter: %w", err)) } app.registerStopFn(func() { @@ -204,20 +204,20 @@ func (app *App) Start(opts ...appOption) error { serverID, isNewInstall, err := testDB.ServerID() if err != nil { - return err + return fmt.Errorf("could not get server ID: %w", err) } app.serverID = serverID err = app.initAnalytics(configFromDB) if err != nil { - return err + return fmt.Errorf("could not init analytics: %w", err) } fmt.Println("New install?", isNewInstall) if isNewInstall { err = analytics.SendEvent("Install", "beacon", "", nil) if err != nil { - return err + return fmt.Errorf("could not send install event: %w", err) } } @@ -304,7 +304,7 @@ func (app *App) Start(opts ...appOption) error { err = analytics.SendEvent("Server Started", "beacon", "", nil) if err != nil { - return err + return fmt.Errorf("could not send server started event: %w", err) } provisioner := provisioning.New() diff --git a/server/cmd/root.go b/server/cmd/root.go index a8b1de5f0f..61adeb804d 100644 --- a/server/cmd/root.go +++ b/server/cmd/root.go @@ -21,7 +21,7 @@ var ( var err error appInstance, err = app.New(cfg) if err != nil { - return err + return fmt.Errorf("cannot create app instance: %w", err) } return nil @@ -44,7 +44,7 @@ func init() { config.WithLogger(log.Default()), ) if err != nil { - fmt.Println(err.Error()) + fmt.Println("error loading config:", err.Error()) os.Exit(1) } }) diff --git a/server/cmd/serve.go b/server/cmd/serve.go index 180dd5c1cb..182e0b7625 100644 --- a/server/cmd/serve.go +++ b/server/cmd/serve.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "os/signal" "sync" @@ -45,6 +46,7 @@ var serveCmd = &cobra.Command{ wg.Add(1) err := appInstance.Start(app.WithProvisioningFile(provisioningFile)) if err != nil { + fmt.Println("Error starting server:", err.Error()) return err } diff --git a/server/config/appconfig.go b/server/config/appconfig.go index 28388a7ee4..86cea6447f 100644 --- a/server/config/appconfig.go +++ b/server/config/appconfig.go @@ -44,7 +44,7 @@ func New(confOpts ...Option) (*AppConfig, error) { err = cfg.vp.Unmarshal(&cfg.config) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot unmarshal config: %w", err) } if err := cfg.Validate(); err != nil {