Skip to content

Commit

Permalink
Merge pull request #12 from objenious/change/lib
Browse files Browse the repository at this point in the history
use objenious/errors
  • Loading branch information
b-2-83 authored Apr 26, 2021
2 parents d9622c3 + 6491c77 commit f861e14
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ backoffutil.Retry(func() error {

## Notes

errorutil is compatible with https://github.com/pkg/errors :
errorutil is compatible with https://github.com/objenious/errors :

```go
err = errors.Wrap(errorutil.RetryableError(err), "some message")
Expand Down
4 changes: 2 additions & 2 deletions delayed.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package errorutil

import (
"github.com/pkg/errors"
"time"

"github.com/objenious/errors"
)

// Delayer defines an error that
Expand Down Expand Up @@ -48,7 +49,6 @@ type delayedError struct {
duration time.Duration
}


func (err *delayedError) Delay() time.Duration {
return err.duration
}
Expand Down
3 changes: 2 additions & 1 deletion delayed_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package errorutil

import (
"github.com/pkg/errors"
"testing"
"time"

"github.com/objenious/errors"
)

func TestDelay(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ see backoffutil sub package
Notes
errorutil is compatible with https://github.com/pkg/errors :
errorutil is compatible with https://github.com/objenious/errors :
err = errors.Wrap(errorutil.RetryableError(err), "some message")
errorutil.IsRetryable(err) // returns true
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/objenious/errorutil
go 1.13

require (
cloud.google.com/go v0.45.1
cloud.google.com/go/storage v1.15.0
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/pkg/errors v0.8.1
github.com/objenious/errors v0.9.1
)
386 changes: 373 additions & 13 deletions go.sum

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"cloud.google.com/go/storage"

pkgerrors "github.com/pkg/errors"
oerrors "github.com/objenious/errors"
)

func TestHTTPStatusCode(t *testing.T) {
Expand All @@ -22,29 +22,29 @@ func TestHTTPStatusCode(t *testing.T) {
{errors.New("foo"), http.StatusInternalServerError},

{os.ErrNotExist, http.StatusNotFound},
{pkgerrors.Wrap(os.ErrNotExist, "bar"), http.StatusNotFound},
{oerrors.Wrap(os.ErrNotExist, "bar"), http.StatusNotFound},
{os.ErrPermission, http.StatusForbidden},
{pkgerrors.Wrap(os.ErrPermission, "bar"), http.StatusForbidden},
{oerrors.Wrap(os.ErrPermission, "bar"), http.StatusForbidden},
{sql.ErrNoRows, http.StatusNotFound},
{pkgerrors.Wrap(sql.ErrNoRows, "bar"), http.StatusNotFound},
{oerrors.Wrap(sql.ErrNoRows, "bar"), http.StatusNotFound},
{storage.ErrBucketNotExist, http.StatusNotFound},
{pkgerrors.Wrap(storage.ErrBucketNotExist, "bar"), http.StatusNotFound},
{oerrors.Wrap(storage.ErrBucketNotExist, "bar"), http.StatusNotFound},
{storage.ErrObjectNotExist, http.StatusNotFound},
{pkgerrors.Wrap(storage.ErrObjectNotExist, "bar"), http.StatusNotFound},
{oerrors.Wrap(storage.ErrObjectNotExist, "bar"), http.StatusNotFound},

{httpError(http.StatusNotFound), http.StatusNotFound},
{pkgerrors.Wrap(httpError(http.StatusNotFound), "bar"), http.StatusNotFound},
{oerrors.Wrap(httpError(http.StatusNotFound), "bar"), http.StatusNotFound},
{httpError(http.StatusForbidden), http.StatusForbidden},
{pkgerrors.Wrap(httpError(http.StatusForbidden), "bar"), http.StatusForbidden},
{oerrors.Wrap(httpError(http.StatusForbidden), "bar"), http.StatusForbidden},

{NotFoundError(errors.New("foo")), http.StatusNotFound},
{pkgerrors.Wrap(NotFoundError(errors.New("foo")), "bar"), http.StatusNotFound},
{oerrors.Wrap(NotFoundError(errors.New("foo")), "bar"), http.StatusNotFound},
{ForbiddenError(errors.New("foo")), http.StatusForbidden},
{pkgerrors.Wrap(ForbiddenError(errors.New("foo")), "bar"), http.StatusForbidden},
{oerrors.Wrap(ForbiddenError(errors.New("foo")), "bar"), http.StatusForbidden},
{InvalidError(errors.New("foo")), http.StatusBadRequest},
{pkgerrors.Wrap(InvalidError(errors.New("foo")), "bar"), http.StatusBadRequest},
{oerrors.Wrap(InvalidError(errors.New("foo")), "bar"), http.StatusBadRequest},
{ConflictError(errors.New("foo")), http.StatusConflict},
{pkgerrors.Wrap(ConflictError(errors.New("foo")), "bar"), http.StatusConflict},
{oerrors.Wrap(ConflictError(errors.New("foo")), "bar"), http.StatusConflict},
}
for _, tt := range tests {
got := HTTPStatusCode(tt.err)
Expand Down
66 changes: 33 additions & 33 deletions retryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"testing"

pkgerrors "github.com/pkg/errors"
oerrors "github.com/objenious/errors"
)

type retryable bool
Expand All @@ -29,55 +29,55 @@ func TestIsRetryable(t *testing.T) {
{nil, false},
{RetryableError(nil), false},
{NotRetryableError(nil), false},
{pkgerrors.Wrap(RetryableError(nil), "bar"), false},
{oerrors.Wrap(RetryableError(nil), "bar"), false},

{errors.New("foo"), false},
{pkgerrors.New("foo"), false},
{pkgerrors.Wrap(errors.New("foo"), "bar"), false},
{oerrors.New("foo"), false},
{oerrors.Wrap(errors.New("foo"), "bar"), false},

{RetryableError(errors.New("foo")), true},
{RetryableError(pkgerrors.New("foo")), true},
{pkgerrors.Wrap(RetryableError(errors.New("foo")), "bar"), true},
{RetryableError(oerrors.New("foo")), true},
{oerrors.Wrap(RetryableError(errors.New("foo")), "bar"), true},

{RetryableError(NotRetryableError(errors.New("foo"))), true},
{NotRetryableError(errors.New("foo")), false},
{NotRetryableError(pkgerrors.New("foo")), false},
{pkgerrors.Wrap(NotRetryableError(errors.New("foo")), "bar"), false},
{NotRetryableError(oerrors.New("foo")), false},
{oerrors.Wrap(NotRetryableError(errors.New("foo")), "bar"), false},

{httpError(http.StatusBadGateway), true},
{pkgerrors.Wrap(httpError(http.StatusBadGateway), "bar"), true},
{oerrors.Wrap(httpError(http.StatusBadGateway), "bar"), true},
{httpError(http.StatusInternalServerError), true},
{pkgerrors.Wrap(httpError(http.StatusInternalServerError), "bar"), true},
{oerrors.Wrap(httpError(http.StatusInternalServerError), "bar"), true},
{httpError(http.StatusGatewayTimeout), true},
{pkgerrors.Wrap(httpError(http.StatusGatewayTimeout), "bar"), true},
{oerrors.Wrap(httpError(http.StatusGatewayTimeout), "bar"), true},
{httpError(429), true},
{pkgerrors.Wrap(httpError(429), "bar"), true},
{oerrors.Wrap(httpError(429), "bar"), true},
{httpError(http.StatusNotFound), false},
{pkgerrors.Wrap(httpError(http.StatusNotFound), "bar"), false},
{oerrors.Wrap(httpError(http.StatusNotFound), "bar"), false},
{NotFoundError(errors.New("foo")), false},
{httpError(http.StatusBadRequest), false},
{pkgerrors.Wrap(httpError(http.StatusBadRequest), "bar"), false},
{oerrors.Wrap(httpError(http.StatusBadRequest), "bar"), false},
{InvalidError(errors.New("foo")), false},
{httpError(http.StatusForbidden), false},
{pkgerrors.Wrap(httpError(http.StatusForbidden), "bar"), false},
{oerrors.Wrap(httpError(http.StatusForbidden), "bar"), false},
{ForbiddenError(errors.New("foo")), false},

{NotRetryableError(httpError(http.StatusBadGateway)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(http.StatusBadGateway), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(http.StatusBadGateway), "bar")), false},
{NotRetryableError(httpError(http.StatusInternalServerError)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(http.StatusInternalServerError), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(http.StatusInternalServerError), "bar")), false},
{NotRetryableError(httpError(http.StatusGatewayTimeout)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(http.StatusGatewayTimeout), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(http.StatusGatewayTimeout), "bar")), false},
{NotRetryableError(httpError(429)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(429), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(429), "bar")), false},
{NotRetryableError(httpError(http.StatusNotFound)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(http.StatusNotFound), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(http.StatusNotFound), "bar")), false},
{NotRetryableError(NotFoundError(errors.New("foo"))), false},
{NotRetryableError(httpError(http.StatusBadRequest)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(http.StatusBadRequest), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(http.StatusBadRequest), "bar")), false},
{NotRetryableError(InvalidError(errors.New("foo"))), false},
{NotRetryableError(httpError(http.StatusForbidden)), false},
{NotRetryableError(pkgerrors.Wrap(httpError(http.StatusForbidden), "bar")), false},
{NotRetryableError(oerrors.Wrap(httpError(http.StatusForbidden), "bar")), false},
{NotRetryableError(ForbiddenError(errors.New("foo"))), false},

{retryable(false), false},
Expand Down Expand Up @@ -110,23 +110,23 @@ func TestIsNotRetryable(t *testing.T) {
{nil, false},
{RetryableError(nil), false},
{NotRetryableError(nil), false},
{pkgerrors.Wrap(RetryableError(nil), "bar"), false},
{NotRetryableError(pkgerrors.Wrap(RetryableError(nil), "bar")), false},
{oerrors.Wrap(RetryableError(nil), "bar"), false},
{NotRetryableError(oerrors.Wrap(RetryableError(nil), "bar")), false},

{errors.New("foo"), false},
{pkgerrors.New("foo"), false},
{pkgerrors.Wrap(errors.New("foo"), "bar"), false},
{oerrors.New("foo"), false},
{oerrors.Wrap(errors.New("foo"), "bar"), false},

{RetryableError(errors.New("foo")), false},
{NotRetryableError(errors.New("foo")), true},
{NotRetryableError(RetryableError(errors.New("foo"))), true},
{RetryableError(pkgerrors.New("foo")), false},
{NotRetryableError(RetryableError(pkgerrors.New("foo"))), true},
{NotRetryableError(pkgerrors.New("foo")), true},
{pkgerrors.Wrap(RetryableError(errors.New("foo")), "bar"), false},
{pkgerrors.Wrap(NotRetryableError(errors.New("foo")), "bar"), true},
{NotRetryableError(pkgerrors.Wrap(RetryableError(errors.New("foo")), "bar")), true},
{RetryableError(NotRetryableError(pkgerrors.Wrap(RetryableError(errors.New("foo")), "bar"))), false},
{RetryableError(oerrors.New("foo")), false},
{NotRetryableError(RetryableError(oerrors.New("foo"))), true},
{NotRetryableError(oerrors.New("foo")), true},
{oerrors.Wrap(RetryableError(errors.New("foo")), "bar"), false},
{oerrors.Wrap(NotRetryableError(errors.New("foo")), "bar"), true},
{NotRetryableError(oerrors.Wrap(RetryableError(errors.New("foo")), "bar")), true},
{RetryableError(NotRetryableError(oerrors.Wrap(RetryableError(errors.New("foo")), "bar"))), false},

{retryable(false), true},
{retryable(true), false},
Expand Down

0 comments on commit f861e14

Please sign in to comment.