diff --git a/factory.go b/factory.go index e8d5290..53837a8 100644 --- a/factory.go +++ b/factory.go @@ -20,6 +20,13 @@ type Falta struct { error } +func NewError(msg string) Falta { + return Falta{ + errFmt: msg, + error: fmt.Errorf(msg), + } +} + // Wrap wraps the error provided with the Falta instance. func (f Falta) Wrap(err error) Falta { f.error = fmt.Errorf("%s: %w", f.error.Error(), err) diff --git a/factory_test.go b/factory_test.go index 05d90b8..2810834 100644 --- a/factory_test.go +++ b/factory_test.go @@ -114,3 +114,10 @@ func TestCapture(t *testing.T) { as.ErrorIs(err, errCannotOpenFile) } + +func TestNewError(t *testing.T) { + err := falta.NewError("falta test: test error") + wrappedErr := fmt.Errorf("wrapped error: %w", err) + as := assert.New(t) + as.ErrorIs(wrappedErr, err) +} diff --git a/go.mod b/go.mod index 18d85c6..3da07ca 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,14 @@ module github.com/a20r/falta -go 1.20 +go 1.21 -require github.com/a20r/mesa v0.5.2 +require ( + github.com/a20r/mesa v0.5.2 + github.com/stretchr/testify v1.8.4 +) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index bdbfcc1..7e811ad 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=