Skip to content

Commit

Permalink
Add wrapper for errors.Join (#2)
Browse files Browse the repository at this point in the history
Had to upgrade to Go 1.20 to add it.
  • Loading branch information
markuswustenberg authored Sep 13, 2024
1 parent 6b461e4 commit 5dc5f90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
// Package errors provides Wrap in addition to the functions in the stdlib errors package.
// It's otherwise a drop-in replacement for the stdlib package.
// Package errors provides [Wrap] in addition to the functions in the [errors] package.
// It also provides [Newf] which is a wrapper around [fmt.Errorf].
package errors

import (
"errors"
"fmt"
)

// As calls errors.As.
// As calls [errors.As].
func As(err error, target interface{}) bool {
return errors.As(err, target)
}

// Is calls errors.Is.
// Is calls [errors.Is].
func Is(err, target error) bool {
return errors.Is(err, target)
}

// New calls errors.New.
// Join calls [errors.Join].
func Join(errs ...error) error {
return errors.Join(errs...)
}

// New calls [errors.New].
func New(text string) error {
return errors.New(text)
}

// Newf calls fmt.Errorf.
// Newf calls [fmt.Errorf].
func Newf(format string, a ...interface{}) error {
return fmt.Errorf(format, a...)
}

// Unwrap calls errors.Unwrap.
// Unwrap calls [errors.Unwrap].
func Unwrap(err error) error {
return errors.Unwrap(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module maragu.dev/errors

go 1.18
go 1.20

0 comments on commit 5dc5f90

Please sign in to comment.