Skip to content

Commit

Permalink
bump to v3.0.5
Browse files Browse the repository at this point in the history
- v3.0.5
  - break out `New(...).Attach(...)`, instead of `New(...).WithErrors(...)`, so that we can make the type architecture clearly and concisely.
  - `Builable` and `Error` interface are the abstract representations about our error objects.
  - bugs fixed
  - more godoc
  • Loading branch information
hedzr committed Feb 22, 2022
1 parent b5affab commit 33513cf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,26 @@ jobs:
## asset_content_type: application/zip

# notifies coveralls that all test jobs are finished
finish:
name: Finish
finish-cov:
name: Finish Coverage
needs: coverage
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true

do-release:
runs-on: ubuntu-latest
needs: coverage
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')





Expand Down
49 changes: 38 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ Wrapped errors and more for golang developing (not just for go1.13+).
import "gopkg.in/hedzr/errors.v3"
```

## History

- v3.0.5
- break out `New(...).Attach(...)`, instead of `New(...).WithErrors(...)`, so that we can make the type architecture clearly and concisely.
- `Builable` and `Error` interface are the abstract representations about our error objects.
- bugs fixed
- more godoc

- v3.0.3
- review the backward compatibilities

- v3.0.0
- rewrite most codes and cleanup multiple small types
- use `New(...)` or `NewBuilder()` to make an error with code, message, inner error(s) and customizable stacktrace info.

## Features

These features are supported for compatibilities.

#### stdlib `errors' compatibilities

- `func As(err error, target interface{}) bool`
Expand All @@ -36,13 +53,14 @@ import "gopkg.in/hedzr/errors.v3"
- [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)`;

#### Others

- Codes
- Inner errors
- Inner errors
We like the flatter inner errors more than the cascade chain, so the `Format("%w)` is a so-so approach to collect the errors. We believe the error slice is a better choice.
- Unwrap inner errors one by one

## Best Practices
Expand All @@ -51,20 +69,25 @@ import "gopkg.in/hedzr/errors.v3"
package test

import (
"gopkg.in/hedzr/errors.v2"
"gopkg.in/hedzr/errors.v3"
"io"
"reflect"
"testing"
)

func TestForExample(t *testing.T) {

err := errors.New("some tips %v", "here")
fn := func() (err error) {
ec := errors.New("some tips %v", "here")
defer ec.Defer(&err)

// attaches much more errors
for _, e := range []error{io.EOF, io.ErrClosedPipe} {
_ = err.Attach(e)
// attaches much more errors
for _, e := range []error{io.EOF, io.ErrClosedPipe} {
ec.Attach(e)
}
}

err := fn()
t.Logf("failed: %+v", err)

// use another number different to default to skip the error frames
Expand Down Expand Up @@ -99,13 +122,17 @@ func TestForExample(t *testing.T) {
if errors.As(err, &a1) {
println(len(a1)) // = 3, means [io.EOF, io.ErrShortWrite, io.ErrClosedPipe]
}
// Or use Causes() to extract them:
if reflect.DeepEqual(a1, errors.Causes(err)) {
t.Fatal("unexpected problem")
}

// As error, the first inner error will be extracted
var ee1 error
if errors.As(err, &ee1) {
println(ee1) // = io.EOF
}

series := []error{io.EOF, io.ErrShortWrite, io.ErrClosedPipe, errors.Internal}
var index int
for ; ee1 != nil; index++ {
Expand All @@ -119,10 +146,10 @@ func TestForExample(t *testing.T) {
func TestContainer(t *testing.T) {
// as a inner errors container
child := func() (err error) {
errContainer := errors.New("")
errContainer := errors.New("multiple tasks have errors")

defer errContainer.Defer(&err)
for _, r:=range []error{io.EOF, io.ErrShortWrite, io.ErrClosedPipe, errors.Internal} {
for _, r := range []error{io.EOF, io.ErrShortWrite, io.ErrClosedPipe, errors.Internal} {
errContainer.Attach(r)
}

Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
// AppName const
AppName = "errors"
// Version const
Version = "3.0.3"
Version = "3.0.5"
// VersionInt const
VersionInt = 0x030003
VersionInt = 0x030005
)

0 comments on commit 33513cf

Please sign in to comment.