Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesfsp committed Sep 27, 2021
1 parent 6e6370d commit 9779123
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
22 changes: 14 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Roadmap

## [0.0.2] - 2021-09-27

### Changed

- `Wrap` now accepts a list of errors.

## [0.0.1] - 2021-09-24

### Checklist
Expand Down Expand Up @@ -34,11 +40,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [x] Ability to create custom errors
- [x] Ability to create custom errors with code
- [x] Ability to create custom errors with status code
- [x] Ability to create custom errors with message
- [x] Ability to create custom errors wrapping an error
- [x] Ability to create static (pre-created) custom errors
- [x] Ability to create dynamic (in-line) custom errors
- [x] Ability to print a custom error with a dynamic, and custom message
- [x] Ability to create custom errors.
- [x] Ability to create custom errors with code.
- [x] Ability to create custom errors with status code.
- [x] Ability to create custom errors with message.
- [x] Ability to create custom errors wrapping an error.
- [x] Ability to create static (pre-created) custom errors.
- [x] Ability to create dynamic (in-line) custom errors.
- [x] Ability to print a custom error with a dynamic, and custom message.
15 changes: 12 additions & 3 deletions customerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"net/http"
"strings"

"github.com/go-playground/validator/v10"
)
Expand Down Expand Up @@ -67,9 +68,17 @@ func (cE *CustomError) Unwrap() error {
return cE.Err
}

// Wrap `customError` around `err`.
func Wrap(customError, err error) error {
return fmt.Errorf("%w. Wrapped Error: %s", customError, err)
// Wrap `customError` around `errors`.
func Wrap(customError error, errors ...error) error {
errMsgs := []string{}

for _, err := range errors {
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
}

return fmt.Errorf("%w. Wrapped Error(s): %s", customError, strings.Join(errMsgs, ". "))
}

//////
Expand Down
2 changes: 1 addition & 1 deletion customerror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestNew_deepNestedErrors(t *testing.T) {
t.Errorf("Expected %v be ErrLayered", errWrapped)
}

expectedErrWrappedMsg := "custom message. Original Error: layer 3. layer 2. layer 1. Wrapped Error: Some error"
expectedErrWrappedMsg := "custom message. Original Error: layer 3. layer 2. layer 1. Wrapped Error(s): Some error"

if errWrapped.Error() != expectedErrWrappedMsg {
t.Errorf("Expected %v to be %s", errWrapped.Error(), expectedErrWrappedMsg)
Expand Down

0 comments on commit 9779123

Please sign in to comment.