Skip to content

Commit

Permalink
Replace log...Fatal() calls with returned errors. (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
timburks authored Apr 6, 2023
1 parent e9340da commit 2b74ea4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/registry/cmd/compute/lintstats/lintstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Command() *cobra.Command {

adminClient, err := connection.NewAdminClientWithSettings(ctx, c)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to get client")
return err
}

return matchAndHandleLintStatsCmd(ctx, client, adminClient, args[0], filter, linter, dryRun)
Expand Down
2 changes: 1 addition & 1 deletion cmd/registry/cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Command() *cobra.Command {
ctx := cmd.Context()
c, err := connection.ActiveConfig()
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to get config")
return err
}
pattern := c.FQName(args[0])
registryClient, err := connection.NewRegistryClientWithSettings(ctx, c)
Expand Down
3 changes: 1 addition & 2 deletions cmd/registry/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/connection"
"github.com/apigee/registry/pkg/encoding"
"github.com/apigee/registry/pkg/log"
"github.com/apigee/registry/pkg/visitor"
"github.com/apigee/registry/rpc"
"github.com/spf13/cobra"
Expand All @@ -46,7 +45,7 @@ func Command() *cobra.Command {
ctx := cmd.Context()
c, err := connection.ActiveConfig()
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to get config")
return err
}
pattern := c.FQName(args[0])
registryClient, err := connection.NewRegistryClientWithSettings(ctx, c)
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/upload/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func discoveryCommand() *cobra.Command {
}
client, err := connection.NewRegistryClient(ctx)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to get client")
return err
}
if err := visitor.VerifyLocation(ctx, client, parent); err != nil {
return fmt.Errorf("parent does not exist (%s)", err)
Expand All @@ -73,7 +73,7 @@ func discoveryCommand() *cobra.Command {

discoveryResponse, err := fetchDiscoveryList(service)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to fetch discovery list")
return fmt.Errorf("failed to fetch discovery list: %s", err)
}

// Create an upload job for each API.
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/upload/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func openAPICommand() *cobra.Command {
}
client, err := connection.NewRegistryClient(ctx)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to get client")
return err
}
if err := visitor.VerifyLocation(ctx, client, parent); err != nil {
return fmt.Errorf("parent does not exist (%s)", err)
Expand All @@ -65,7 +65,7 @@ func openAPICommand() *cobra.Command {
for _, arg := range args {
path, err := filepath.Abs(arg)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Invalid path")
return fmt.Errorf("invalid path: %s", err)
}
scanDirectoryForOpenAPI(ctx, client, parent, baseURI, path, taskQueue)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/registry/cmd/upload/protos.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func protosCommand() *cobra.Command {
}
client, err := connection.NewRegistryClient(ctx)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Failed to get client")
return err
}
if err := visitor.VerifyLocation(ctx, client, parent); err != nil {
return fmt.Errorf("parent does not exist (%s)", err)
Expand All @@ -82,15 +82,15 @@ func protosCommand() *cobra.Command {
for _, arg := range args {
path, err := filepath.Abs(arg)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Invalid path")
return fmt.Errorf("invalid path: %s", err)
}

if root == "" {
root = path
}
root, err := filepath.Abs(root)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("Invalid path")
return fmt.Errorf("invalid path: %s", err)
}

if err := scanDirectoryForProtos(client, parent, baseURI, path, root, taskQueue); err != nil {
Expand Down

0 comments on commit 2b74ea4

Please sign in to comment.