-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix hidden in log wrapped error message
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
// } | ||
} |