Skip to content

Commit

Permalink
Merge pull request #211 from tonytheleg/RHCLOUD-35835-enhance-cmd-errors
Browse files Browse the repository at this point in the history
RHCLOUD-35835: improves error messages for base commands
  • Loading branch information
tonytheleg authored Oct 29, 2024
2 parents 93766cf + 3e66acc commit b555b36
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion internal/authn/authn.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package authn

import (
"fmt"
"github.com/go-kratos/kratos/v2/log"
"github.com/project-kessel/inventory-api/internal/authn/api"
"github.com/project-kessel/inventory-api/internal/authn/clientcert"
Expand Down Expand Up @@ -31,7 +32,7 @@ func New(config CompletedConfig, logger *log.Helper) (api.Authenticator, error)
if a, err := oidc.New(*config.Oidc); err == nil {
d.Add(a)
} else {
return nil, err
return nil, fmt.Errorf("failed to load OIDC info: %v", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/authn/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func New(c CompletedConfig) (*OAuth2Authenticator, error) {
ctx := coreosoidc.ClientContext(context.Background(), c.Client)
provider, err := coreosoidc.NewProvider(ctx, c.AuthorizationServerURL)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create provider: %v", err)
}

if c.PrincipalUserDomain == "" {
Expand Down
8 changes: 5 additions & 3 deletions internal/data/migrate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package data

import (
"fmt"

"github.com/project-kessel/inventory-api/internal/biz/model"
"gorm.io/gorm"

Expand All @@ -19,20 +21,20 @@ func Migrate(db *gorm.DB, logger *log.Helper) error {
}

if err := db.AutoMigrate(models...); err != nil {
return err
return fmt.Errorf("auto migration has failed: %v", err)
}

for _, m := range models {
if gormDbIndexStatement, ok := m.(model.GormDbAfterMigrationHook); ok {
statement := &gorm.Statement{DB: db}
err := statement.Parse(m)
if err != nil {
return err
return fmt.Errorf("statement parsing has failed: %v", err)
}

err = gormDbIndexStatement.GormDbAfterMigration(db, statement.Schema)
if err != nil {
return err
return fmt.Errorf("migration failure: %v", err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/eventing/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func New(c CompletedConfig, source string, logger *log.Helper) (api.Manager, err
case "kafka":
km, err := kafka.New(c.Kafka, source, logger)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create kafka manager: %w", err)
}
return km, nil
}
Expand Down
9 changes: 5 additions & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"fmt"

"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
Expand Down Expand Up @@ -33,22 +34,22 @@ func New(c CompletedConfig, authn middleware.Middleware, logger log.Logger) (*Se

meterProvider, err := NewMeterProvider(s)
if err != nil {
return nil, err
return nil, fmt.Errorf("init meter provider failed: %v", err)
}

meter, err := NewMeter(meterProvider)
if err != nil {
return nil, err
return nil, fmt.Errorf("init meter failed: %v", err)
}

httpServer, err := http.New(c.HttpConfig, authn, meter, logger)
if err != nil {
return nil, err
return nil, fmt.Errorf("init http server failed: %v", err)
}

grpcServer, err := grpc.New(c.GrpcConfig, authn, meter, logger)
if err != nil {
return nil, err
return nil, fmt.Errorf("init grpc server failed: %v", err)
}

s.HttpServer = httpServer
Expand Down

0 comments on commit b555b36

Please sign in to comment.