Skip to content

Commit

Permalink
chore: update output rendering of error catalog errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sandor-trombitas authored and j-luong committed Feb 17, 2025
1 parent 7cf88b1 commit 07a6799
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 51 deletions.
1 change: 1 addition & 0 deletions cliv2/cmd/cliv2/logheaderfooter.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func writeLogFooter(exitCode int, errs []error) {
}
}
}
tablePrint("Interaction", interactionId)
tablePrint("Exit Code", strconv.Itoa(exitCode))
}

Expand Down
18 changes: 9 additions & 9 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ import (
"github.com/snyk/cli-extension-dep-graph/pkg/depgraph"
"github.com/snyk/cli-extension-iac-rules/iacrules"
"github.com/snyk/cli-extension-sbom/pkg/sbom"
"github.com/snyk/cli/cliv2/internal/cliv2"
"github.com/snyk/cli/cliv2/internal/constants"
"github.com/snyk/container-cli/pkg/container"
"github.com/snyk/go-application-framework/pkg/analytics"
"github.com/snyk/go-application-framework/pkg/app"
"github.com/snyk/go-application-framework/pkg/configuration"
"github.com/snyk/go-application-framework/pkg/instrumentation"
"github.com/snyk/go-application-framework/pkg/local_workflows/network_utils"
"github.com/snyk/go-application-framework/pkg/local_workflows/output_workflow"
"github.com/snyk/go-application-framework/pkg/networking/middleware"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/snyk/cli/cliv2/internal/cliv2"
"github.com/snyk/cli/cliv2/internal/constants"

localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows"
"github.com/snyk/go-application-framework/pkg/local_workflows/content_type"
"github.com/snyk/go-application-framework/pkg/local_workflows/json_schemas"
Expand All @@ -57,7 +57,7 @@ var helpProvided bool

var noopLogger zerolog.Logger = zerolog.New(io.Discard)
var globalLogger *zerolog.Logger = &noopLogger
var interactionId = uuid.NewString()
var interactionId = instrumentation.AssembleUrnFromUUID(uuid.NewString())

const (
unknownCommandMessage string = "unknown command"
Expand Down Expand Up @@ -453,7 +453,7 @@ func handleError(err error) HandleError {
return resultError
}

func displayError(err error, userInterface ui.UserInterface, config configuration.Configuration) {
func displayError(err error, userInterface ui.UserInterface, config configuration.Configuration, interactionId string) {
if err != nil {
_, isExitError := err.(*exec.ExitError)
_, isErrorWithCode := err.(*cli_errors.ErrorWithExitCode)
Expand All @@ -471,10 +471,10 @@ func displayError(err error, userInterface ui.UserInterface, config configuratio
jsonErrorBuffer, _ := json.MarshalIndent(jsonError, "", " ")
userInterface.Output(string(jsonErrorBuffer))
} else {
if errors.Is(err, context.DeadlineExceeded) {
err = fmt.Errorf("command timed out")
meta := map[string]interface{}{
"interactionId": interactionId,
}

err = middleware.AddMetaDataToErr(err, meta)
uiError := userInterface.OutputError(err)
if uiError != nil {
globalLogger.Err(uiError).Msg("ui failed to show error")
Expand Down Expand Up @@ -607,7 +607,7 @@ func MainWithErrorCode() (int, []error) {
err = legacyCLITerminated(err, errorList)
}

displayError(err, globalEngine.GetUserInterface(), globalConfiguration)
displayError(err, globalEngine.GetUserInterface(), globalConfiguration, interactionId)

exitCode := cliv2.DeriveExitCode(err)
globalLogger.Printf("Deriving Exit Code %d (cause: %v)", exitCode, err)
Expand Down
30 changes: 16 additions & 14 deletions cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/snyk/cli-extension-sbom v0.0.0-20241016065306-0df2be5b3b8f
github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7
github.com/snyk/error-catalog-golang-public v0.0.0-20250121101159-e6a61b2bfae6
github.com/snyk/go-application-framework v0.0.0-20250212121528-2e787c13a2cc
github.com/snyk/go-application-framework v0.0.0-20250217170103-665eb3dfd392
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20250213084108-c87400c00e06
Expand Down Expand Up @@ -64,15 +64,15 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/denisbrodbeck/machineid v1.0.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/erikgeiser/promptkit v0.8.0 // indirect
github.com/erni27/imcache v1.2.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gertd/go-pluralize v0.2.1 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/getkin/kin-openapi v0.129.0 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.1 // indirect
Expand Down Expand Up @@ -109,7 +109,6 @@ require (
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
Expand All @@ -123,7 +122,7 @@ require (
github.com/klauspost/compress v1.17.9 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
Expand All @@ -141,6 +140,8 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/oasdiff/yaml v0.0.0-20241214135536-5f7845c759c8 // indirect
github.com/oasdiff/yaml3 v0.0.0-20241214160948-977117996672 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/open-policy-agent/opa v0.69.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand Down Expand Up @@ -172,7 +173,8 @@ require (
github.com/snyk/policy-engine v0.33.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd // indirect
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
github.com/speakeasy-api/jsonpath v0.6.1 // indirect
github.com/speakeasy-api/openapi-overlay v0.10.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/viper v1.18.2 // indirect
Expand Down Expand Up @@ -202,17 +204,17 @@ require (
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.29.0 // indirect
golang.org/x/tools v0.30.0 // indirect
google.golang.org/api v0.195.0 // indirect
google.golang.org/genproto v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
Expand Down
Loading

0 comments on commit 07a6799

Please sign in to comment.