From e4c6d857ebcdccf756babb9e473081007a9746ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Albi?= Date: Fri, 8 Dec 2023 21:16:16 +0100 Subject: [PATCH] feat: remove gRPC info from Ignite Apps errors (#3830) * feat: remove gRPC info from Ignite Apps errors * chore: update changelog --- changelog.md | 4 ++++ ignite/cmd/ignite/main.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/changelog.md b/changelog.md index 37797bd902..b1b3b574cd 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index afe1b2b3b5..fe57fc8bb3 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -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" @@ -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 @@ -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) +}