Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHCLOUD-35835: improves error messages for base commands #211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading