diff --git a/bundle/render/render_text_output.go b/bundle/render/render_text_output.go index 97a311ad38..37ea188f7c 100644 --- a/bundle/render/render_text_output.go +++ b/bundle/render/render_text_output.go @@ -49,6 +49,10 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }} {{- if .Location.File }} {{ "in " }}{{ .Location.String | cyan }} {{- end }} +{{- if .Detail }} + +{{ .Detail }} +{{- end }} ` @@ -157,9 +161,6 @@ func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) } // RenderTextOutput renders the diagnostics in a human-readable format. -// -// It prints errors and returns root.AlreadyPrintedErr if there are any errors. -// If there are unexpected errors during rendering, it returns an error different from root.AlreadyPrintedErr. func RenderTextOutput(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error { err := renderDiagnostics(out, b, diags) if err != nil { diff --git a/bundle/render/render_text_output_test.go b/bundle/render/render_text_output_test.go index e39a95b461..4ae86ded70 100644 --- a/bundle/render/render_text_output_test.go +++ b/bundle/render/render_text_output_test.go @@ -79,7 +79,7 @@ func TestRenderTextOutput(t *testing.T) { "Found 2 warnings\n", }, { - name: "bundle during 'load' and 2 errors with details", + name: "bundle during 'load' and 2 errors, 1 warning with details", bundle: loadingBundle, diags: diag.Diagnostics{ diag.Diagnostic{ @@ -102,6 +102,16 @@ func TestRenderTextOutput(t *testing.T) { Column: 1, }, }, + diag.Diagnostic{ + Severity: diag.Warning, + Summary: "warning (3)", + Detail: "detail (3)", + Location: dyn.Location{ + File: "foo.py", + Line: 3, + Column: 1, + }, + }, }, expected: "Error: error (1)\n" + " in foo.py:1:1\n" + @@ -113,10 +123,15 @@ func TestRenderTextOutput(t *testing.T) { "\n" + "detail (2)\n" + "\n" + + "Warning: warning (3)\n" + + " in foo.py:3:1\n" + + "\n" + + "detail (3)\n" + + "\n" + "Name: test-bundle\n" + "Target: test-target\n" + "\n" + - "Found 2 errors\n", + "Found 2 errors and 1 warning\n", }, { name: "bundle during 'init'", diff --git a/cmd/root/root.go b/cmd/root/root.go index cc15a27cfe..91e91d368c 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -2,6 +2,7 @@ package root import ( "context" + "errors" "fmt" "os" "strings" @@ -97,7 +98,7 @@ func Execute(cmd *cobra.Command) { // Run the command cmd, err := cmd.ExecuteContextC(ctx) - if err != nil && err != ErrAlreadyPrinted { + if err != nil && errors.Is(err, ErrAlreadyPrinted) { // If cmdio logger initialization succeeds, then this function logs with the // initialized cmdio logger, otherwise with the default cmdio logger cmdio.LogError(cmd.Context(), err)