Skip to content

Commit

Permalink
Add NewError
Browse files Browse the repository at this point in the history
  • Loading branch information
a20r committed Feb 23, 2024
1 parent 2df802d commit 5ab36a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit 5ab36a3

Please sign in to comment.