Added boil error helpers
This commit is contained in:
parent
b7a04e849c
commit
a559738d59
2 changed files with 44 additions and 0 deletions
20
boil/errors.go
Normal file
20
boil/errors.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package boil
|
||||
|
||||
type boilErr struct {
|
||||
error
|
||||
}
|
||||
|
||||
func WrapErr(err error) error {
|
||||
return boilErr{
|
||||
error: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (e boilErr) Error() string {
|
||||
return e.error.Error()
|
||||
}
|
||||
|
||||
func IsBoilErr(err error) bool {
|
||||
_, ok := err.(boilErr)
|
||||
return ok
|
||||
}
|
24
boil/errors_test.go
Normal file
24
boil/errors_test.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package boil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := errors.New("test error")
|
||||
if IsBoilErr(err) == true {
|
||||
t.Errorf("Expected false")
|
||||
}
|
||||
|
||||
err = WrapErr(errors.New("test error"))
|
||||
if err.Error() != "test error" {
|
||||
t.Errorf(`Expected "test error", got %v`, err.Error())
|
||||
}
|
||||
|
||||
if IsBoilErr(err) != true {
|
||||
t.Errorf("Expected true")
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue