Skip to content

Commit

Permalink
Address CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kanterov committed Jul 1, 2024
1 parent 04caf10 commit 6282a4e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions bundle/render/render_text_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }}
{{- if .Location.File }}
{{ "in " }}{{ .Location.String | cyan }}
{{- end }}
{{- if .Detail }}
{{ .Detail }}
{{- end }}
`

Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions bundle/render/render_text_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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" +
Expand All @@ -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'",
Expand Down
3 changes: 2 additions & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package root

import (
"context"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6282a4e

Please sign in to comment.