Skip to content

Commit

Permalink
feat: remove gRPC info from Ignite Apps errors (#3830)
Browse files Browse the repository at this point in the history
* feat: remove gRPC info from Ignite Apps errors

* chore: update changelog
  • Loading branch information
jeronimoalbi authored Dec 8, 2023
1 parent f1d1b48 commit e4c6d85
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- [#3830](https://github.com/ignite/cli/pull/3830) Remove gRPC info from Ignite Apps errors

## [`v28.0.0`](https://github.com/ignite/cli/releases/tag/v28.0.0)

### Features
Expand Down
31 changes: 31 additions & 0 deletions ignite/cmd/ignite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"sync"

"google.golang.org/grpc/status"

ignitecmd "github.com/ignite/cli/v28/ignite/cmd"
chainconfig "github.com/ignite/cli/v28/ignite/config/chain"
"github.com/ignite/cli/v28/ignite/internal/analytics"
Expand Down Expand Up @@ -41,6 +43,10 @@ func run() int {
analytics.SendMetric(&wg, subCmd)

err = cmd.ExecuteContext(ctx)
if err != nil {
err = ensureError(err)
}

if errors.Is(ctx.Err(), context.Canceled) || errors.Is(err, context.Canceled) {
fmt.Println("aborted")
return exitCodeOK
Expand Down Expand Up @@ -75,3 +81,28 @@ func run() int {

return exitCodeOK
}

func ensureError(err error) error {
// Extract gRPC error status.
// These errors are returned by the plugins.
s, ok := status.FromError(err)
if !ok {
// The error is not a gRPC error
return err
}

// Get the error message
cause := s.Proto().GetMessage()
if cause == "" {
return err
}

// Restore context canceled errors
if cause == context.Canceled.Error() {
return context.Canceled
}

// Use the gRPC description as error to avoid printing
// extra gRPC error information like code or prefix.
return errors.New(cause)
}

0 comments on commit e4c6d85

Please sign in to comment.