Skip to content

Commit

Permalink
fix hidden in log wrapped error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Nov 24, 2021
1 parent 4b13d2b commit 34b8b51
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ func printStack(w io.Writer, err error) {
}
c, ok := inner.(causer)
if !ok {
fmt.Fprintf(w, "%d %s\n", stackCounter, inner)
fmt.Fprintf(w, "\ttype: %T\n", inner)
cliCommand.AddError(domain.CliError{
Error: inner.Error(),
Type: fmt.Sprintf("%T", inner),
Expand Down
42 changes: 42 additions & 0 deletions cli/log/log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package log

import (
"bytes"
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func wrap(err error) error {
return Wrap(err)
}

func errSource() error {
return Wrap(fmt.Errorf("my-error"), "hide error")
}

func TestWrap(t *testing.T) {

err := wrap(errSource())
require.Error(t, err)

buf := bytes.NewBuffer(nil)
printStack(buf, err)
t.Logf("\n%s", buf)

require.True(t, strings.Contains(buf.String(), "my-error"))

// //show all causers
// i := 0
// for {
// i++
// fmt.Printf("%d %s %T\n", i, err, err)
// c, ok := err.(causer)
// if !ok {
// break
// }
// err = c.Cause()
// }
}

0 comments on commit 34b8b51

Please sign in to comment.