Skip to content

Commit

Permalink
bump to v3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Jan 11, 2024
1 parent edf4190 commit a7c3cc6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 84 deletions.
29 changes: 16 additions & 13 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# CHANGELOG

- v3.3.1
- fixed Iss() couldn't test the others except the first error.

- v3.3.0
- added `Iss(err, errs...)` to test if any of errors are included in 'err'.
- added `Iss(err, errs...)` to test if any of errors are included in 'err'.
- improved As/Is/Unwrap to fit for new joint error since go1.20
- added causes2.Clear, ...
- improved Error() string
- reviewed
- reviewed and re-published this repo from v3.3

- v3.1.9
- fixed error.Is deep test to check two errors' message text contents if matched
- fixed errors.v3.Join when msg is not empty in an err obj
- fixed causes.WithErrors(): err obj has been ignored even if its message is not empty
- fixed causes.WithErrors() - err obj has been ignored even if its message is not empty

- v3.1.6
- improved/fixed the formatting algorithm on error object
Expand All @@ -36,20 +39,20 @@
- added `Join()` to compliant with go1.20 errors.Join
- reviewed all of testcases

- v3.0.21 ..
- add: `RegisterCode()` at top level for initialize user-defined Coded decl
- godoc and fix/imp Attach() to copy inner errors' StackTrace
- fix Is(): Is(err, errors.BadRequest) might be dead lock or cannot return the test result probably
- new lint + fmr
- imp: remove redundant codes
- update withStackInfo.Stack with WithData() - specially for defer recover codes
- v3.0.21
- added RegisterCode() at top level for initialize user-defined Coded decl.
- godoc and fix/imp Attach() to copy inner errors' StackTrace
- fix Is() - Is(err, errors.BadRequest) might be dead lock or cannot return the test result probably
- new lint + fmt.
- imp - remove redundant codes
- update withStackInfo.Stack with WithData() - specially for defer recover codes

- v3.0.15
- fix: make Is() work for go1.12 and below

- v3.0.13
- fea: IsDescended for error template test
- fix: code and causes are present at same time
- fea - IsDescended for error template test
- fix - code and causes are present at same time

- v3.0.11
- changed the `FormatWith` interface to support error template feature.
Expand All @@ -58,7 +61,7 @@
- support go1.11-17,18+

- v3.0.9
- fix: WithErrors will check IsEmpty on an error container and avoid adding it if empty.
- fix - WithErrors will check IsEmpty on an error container and avoid adding it if empty.

- v3.0.8
- restore error message template
Expand Down
111 changes: 40 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Wrapped errors and more for golang developing (not just for go1.11, go1.13, and

- Simple migrating way from std errors: all of standard functions have been copied to
- Better `New()`:
- format message inline: `err := errors.New("hello %s", "world")`
- format with `WithXXX`: `err := errors.New(errors.WithErrors(errs...))`
- cascade format: `err := errors.New().WithErrors(errs...)`
- Stacktrace awareness
- Container for canning errors: [Error Container (Inner/Nested)](#error-container-innernested)
- error template: [Format message instantly but the text template can be given at beginning](#error-template)
- format message inline: `err := errors.New("hello %s", "world")`
- format with `WithXXX`: `err := errors.New(errors.WithErrors(errs...))`
- cascade format: `err := errors.New().WithErrors(errs...)`
- Stacktrace awareness
- Container for canning errors: [Error Container (Inner/Nested)](#error-container-innernested)
- error template: [Format message instantly but the text template can be given at beginning](#error-template)
- Codes: treat a number as an error object
- Unwrap inner canned errors one by one
- No mental burden
Expand All @@ -31,77 +31,46 @@ Wrapped errors and more for golang developing (not just for go1.11, go1.13, and

## History

- v3.3.1
- fixed Iss() couldn't test the others except the first error.

- v3.3.0
- added `Iss(err, errs...)` to test if any of errors are included in 'err'.
- added `Iss(err, errs...)` to test if any of errors are included in 'err'.
- improved As/Is/Unwrap to fit for new joint error since go1.20
- added causes2.Clear, ...
- improved Error() string
- reviewed
- reviewed and re-published this repo from v3.3

- v3.1.9
- fixed error.Is deep test to check two errors' message text contents if matched
- fixed errors.v3.Join when msg is not empty in an err obj
- fixed causes.WithErrors(): err obj has been ignored even if its message is not empty

- v3.1.6
- improved/fixed the formatting algorithm on error object
- added more builtin error codes, such as IllegalState
- improved godoc
- added TestCodeRegister
- added integral value as suffix of Code error formatted output.

- v3.1.5
- fixed `errors.New("").Attach(errs...)` don't skip the `empty` error.
**Attach ignores an error only if it is nil**.
- fixed the emptiness test for `WithStackInfo`.
- cleanup an unused `if len(errs) > 0`.
- added `WithMaxObjectStringLength(maxObjectStringLen)` for long formatting data/taggedData by
WithData/WithTaggedData

- v3.1.3
- better output of sites and taggedSites
indent and multi-line outputs while formatting with `%+v`

- v3.1.1
- better message format for a nested error, see [Better format](#better-format-for-a-nested-error)

- v3.1.0
- added `Join()` to compliant with go1.20 errors.Join
- reviewed all of testcases

- v3.0.21
- add: `RegisterCode()` at top level for initialize user-defined Coded decl
- godoc and fix/imp Attach() to copy inner errors' StackTrace
- fix Is(): Is(err, errors.BadRequest) might be dead lock or cannot return the test result probably
- new lint + fmr
- imp: remove redundant codes
- update withStackInfo.Stack with WithData() - specially for defer recover codes
- fixed error.Is deep test to check two errors' message text contents if matched
- fixed errors.v3.Join when msg is not empty in an err obj
- fixed causes.WithErrors(): err obj has been ignored even if its message is not empty

- OLDER in [CHANGELOG](https://github.com/hedzr/errors/blob/master/CHANGELOG)

## Compatibilities

These features are supported for compatibilities.

#### stdlib `errors' compatibilities
### stdlib `errors' compatibilities

- `func As(err error, target interface{}) bool`
- `func Is(err, target error) bool`
- `func New(text string) error`
- `func Unwrap(err error) error`
- `func Join(errs ...error) error`

#### `pkg/errors` compatibilities
### `pkg/errors` compatibilities

- `func Wrap(err error, message string) error`
- `func Cause(err error) error`: unwraps recursively, just like Unwrap()
- [x] `func Cause1(err error) error`: unwraps just one level
- `func WithCause(cause error, message string, args ...interface{}) error`, = `Wrap`
- supports Stacktrace
- in an error by `Wrap()`, stacktrace wrapped;
- for your error, attached by `WithStack(cause error)`;
- in an error by `Wrap()`, stacktrace wrapped;
- for your error, attached by `WithStack(cause error)`;

#### Some Enhancements
### Some Enhancements

- `Iss(err error, errs ...error) bool`
- `AsSlice(errs []error, target interface{}) bool`
Expand Down Expand Up @@ -240,11 +209,11 @@ to build an error instantly.
func TestErrorsTmpl(t *testing.T) {
errTmpl := errors.New("expecting %v but got %v")

var err error
err = errTmpl.FormatWith("789", "123")
t.Logf("The error is: %v", err)
err = errTmpl.FormatWith(true, false)
t.Logf("The error is: %v", err)
var err error
err = errTmpl.FormatWith("789", "123")
t.Logf("The error is: %v", err)
err = errTmpl.FormatWith(true, false)
t.Logf("The error is: %v", err)
}
```

Expand All @@ -255,11 +224,11 @@ This relation can be tested by `errors.IsDescent(errTempl, err)`

```go
func TestIsDescended(t *testing.T) {
err3 := New("any error tmpl with %v")
err4 := err3.FormatWith("huahua")
if !IsDescended(err3, err4) {
t.Fatalf("bad test on IsDescended(err3, err4)")
}
err3 := New("any error tmpl with %v")
err4 := err3.FormatWith("huahua")
if !IsDescended(err3, err4) {
t.Fatalf("bad test on IsDescended(err3, err4)")
}
}
```

Expand All @@ -269,13 +238,13 @@ Since v3.1.1, the better message format will be formatted at Printf("%+v").

```go
func TestAs_betterFormat(t *testing.T) {
var err = New("Have errors").WithErrors(io.EOF, io.ErrShortWrite, io.ErrNoProgress)
t.Logf("%v\n", err)

var nestNestErr = New("Errors FOUND:").WithErrors(err, io.EOF)
var nnnErr = New("Nested Errors:").WithErrors(nestNestErr, strconv.ErrRange)
t.Logf("%v\n", nnnErr)
t.Logf("%+v\n", nnnErr)
var err = New("Have errors").WithErrors(io.EOF, io.ErrShortWrite, io.ErrNoProgress)
t.Logf("%v\n", err)
var nestNestErr = New("Errors FOUND:").WithErrors(err, io.EOF)
var nnnErr = New("Nested Errors:").WithErrors(nestNestErr, strconv.ErrRange)
t.Logf("%v\n", nnnErr)
t.Logf("%+v\n", nnnErr)
}
```

Expand All @@ -295,11 +264,11 @@ The output is:
- value out of range

gopkg.in/hedzr/errors%2ev3.TestAs_betterFormat
/Volumes/VolHack/work/godev/cmdr-series/libs/errors/causes_test.go:26
/Volumes/VolHack/work/godev/cmdr-series/libs/errors/causes_test.go:26
testing.tRunner
/usr/local/go/src/testing/testing.go:1576
/usr/local/go/src/testing/testing.go:1576
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1598
/usr/local/go/src/runtime/asm_amd64.s:1598
--- PASS: TestAs_betterFormat (0.00s)
PASS
```
Expand All @@ -310,4 +279,4 @@ MIT

### Scan

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhedzr%2Ferrors.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhedzr%2Ferrors?ref=badge_large)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhedzr%2Ferrors.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhedzr%2Ferrors?ref=badge_large)

0 comments on commit a7c3cc6

Please sign in to comment.