Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions code.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package errutil

// NewCode adds code to an error
func NewCode(err error, code string) error {
if err == nil {
return nil
}

return coded{
wrappedError: wrappedError{error: err},
code: code,
Expand Down
4 changes: 4 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
//
// Wrap(errors.New("my error"), WithAccessDenied(true), WithRateLimit(true))
func Wrap(err error, opts ...OptsFunc) error {
if err == nil {
return nil
}

e := multiKindErr{
opts: ToOpts(opts...),
error: err,
Expand Down
7 changes: 7 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ func TestWrapError(t *testing.T) {
}
})

t.Run("with nil error", func(t *testing.T) {
err := Wrap(nil, WithNotFound())
if err != nil {
t.Fatal("expected nil")
}
})

})

t.Run("should handle tagged errors as expected", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal_error_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package errutil

// NewInternalErrorMessage adds an internal message to an error
func NewInternalErrorMessage(err error, msg string) error {
if err == nil {
return nil
}

return internalErrorMessage{
wrappedError: wrappedError{error: err},
msg: msg,
Expand Down
3 changes: 2 additions & 1 deletion stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package errutil

import (
"fmt"
"github.com/pkg/errors"
"io"
"runtime"

"github.com/pkg/errors"
)

func NewStacked(err error, skip ...int) error {
Expand Down
4 changes: 4 additions & 0 deletions status_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package errutil

// NewStatusCode adds a status code to an error
func NewStatusCode(err error, code int) error {
if err == nil {
return nil
}

return statusCode{
wrappedError: wrappedError{error: err},
code: code,
Expand Down
4 changes: 0 additions & 4 deletions string_error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* Copyright (c) 2022 LucidResolutions LLC. All rights reserved.
*/

package errutil

// StringErr allows you to use a string as an error
Expand Down
4 changes: 4 additions & 0 deletions tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package errutil

// NewTagged adds tags to an error
func NewTagged(err error, tags ...Tag) error {
if err == nil {
return nil
}

return Tagged{
wrappedError: wrappedError{error: err},
tags: tags,
Expand Down