Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Feb 19, 2022
1 parent 8fa9d1d commit 0434828
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Builder interface {
Build() *WithStackInfo

// Attach inner errors for backward compatibility to v2
Attach(errs ...error)
Attach(errs ...error) *WithStackInfo
}

type builder struct {
Expand All @@ -100,8 +100,8 @@ func (s *builder) WithErrors(errs ...error) Builder {

// Attach attaches the given errs as inner errors.
// For backward compatibility to v2
func (s *builder) Attach(errs ...error) {
_ = s.WithErrors(errs...).Build()
func (s *builder) Attach(errs ...error) *WithStackInfo {
return s.WithErrors(errs...).Build()
}

// WithMessage formats the error message
Expand Down
7 changes: 7 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func TestNew(t *testing.T) {
Build()
t.Logf("failed: %+v", err)

err = NewBuilder().
WithCode(Internal).
WithErrors(io.EOF).
WithErrors(io.ErrShortWrite).
Attach(io.ErrClosedPipe)
t.Logf("failed: %+v", err)

err = New(WithErrors(io.EOF, io.ErrShortWrite))
t.Logf("failed: %+v", err)

Expand Down
6 changes: 6 additions & 0 deletions withstackinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ func (w *WithStackInfo) Defer(err *error) {
*err = w
}

// Attach _
func (w *WithStackInfo) Attach(errs ...error) *WithStackInfo {
_ = w.WithErrors(errs...)
return w
}

// Format formats the stack of Frames according to the fmt.Formatter interface.
//
// %s lists source files for each Frame in the stack
Expand Down

0 comments on commit 0434828

Please sign in to comment.