Skip to content

Commit

Permalink
v1.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesfsp committed Nov 4, 2022
1 parent 1410a0b commit 2513825
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.12] - 2022-10-21
### Added
- `WithIgnoreString` now also check the underlying error message for the given string.

## [1.0.11] - 2022-10-21
### Added
- Added the ability to tag errors with a custom tags. Tags is a list of tags which helps to categorize the error.
Expand Down
2 changes: 2 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ func ExampleNew_marshalJSON() {
// Demonstrates the WithIgnoreString option.
func ExampleNew_optionsWithIgnoreString() {
fmt.Println(NewMissingError("id", WithIgnoreString("id")) == nil)
fmt.Println(NewMissingError("id", WithError(errors.New("hehehe")), WithIgnoreString("hehehe")) == nil)
fmt.Println(NewMissingError("id", WithIgnoreString("hahaha")) == nil)

// output:
// true
// true
// false
}

Expand Down
8 changes: 6 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ func WithIgnoreFunc(f func(cE *CustomError) bool) Option {
}
}

// WithIgnoreString ignores an error if the error message contains the specified
// string.
// WithIgnoreString ignores an error if the error message, or the the underlying
// error message contains the specified string.
func WithIgnoreString(s ...string) Option {
return WithIgnoreFunc(func(cE *CustomError) bool {
for _, str := range s {
if strings.Contains(cE.Message, str) {
return true
}

if cE.Err != nil && strings.Contains(cE.Err.Error(), str) {
return true
}
}

return false
Expand Down

0 comments on commit 2513825

Please sign in to comment.