Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make not-found errors discoverable #133

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ env:
global:
- GOTFLAGS="-race -cpu=5"
matrix:
- BUILD_DEPTYPE=gx
- BUILD_DEPTYPE=gomod


Expand All @@ -24,7 +23,6 @@ script:

cache:
directories:
- $GOPATH/src/gx
- $GOPATH/pkg/mod
- $HOME/.cache/go-build

Expand Down
16 changes: 10 additions & 6 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,18 @@ type TxnDatastore interface {

// Errors

type dsError struct {
error
isNotFound bool
}

func (e *dsError) NotFound() bool {
return e.isNotFound
}

// ErrNotFound is returned by Get and GetSize when a datastore does not map the
// given key to a value.
var ErrNotFound = errors.New("datastore: key not found")

// ErrInvalidType is returned by Put when a given value is incopatible with
// the type the datastore supports. This means a conversion (or serialization)
// is needed beforehand.
var ErrInvalidType = errors.New("datastore: invalid type error")
var ErrNotFound error = &dsError{error: errors.New("datastore: key not found"), isNotFound: true}

// GetBackedHas provides a default Datastore.Has implementation.
// It exists so Datastore.Has implementations can use it, like so:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require (
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8
github.com/kr/pretty v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8 changes: 4 additions & 4 deletions mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package mount
import (
"container/heap"
"errors"
"fmt"
"sort"
"strings"
"sync"

ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"
xerrors "golang.org/x/xerrors"
)

var (
Expand Down Expand Up @@ -370,7 +370,7 @@ func (d *Datastore) Check() error {
for _, m := range d.mounts {
if c, ok := m.Datastore.(ds.CheckedDatastore); ok {
if err := c.Check(); err != nil {
return fmt.Errorf("checking datastore at %s: %s", m.Prefix.String(), err.Error())
return xerrors.Errorf("checking datastore at %s: %w", m.Prefix.String(), err)
}
}
}
Expand All @@ -381,7 +381,7 @@ func (d *Datastore) Scrub() error {
for _, m := range d.mounts {
if c, ok := m.Datastore.(ds.ScrubbedDatastore); ok {
if err := c.Scrub(); err != nil {
return fmt.Errorf("scrubbing datastore at %s: %s", m.Prefix.String(), err.Error())
return xerrors.Errorf("scrubbing datastore at %s: %w", m.Prefix.String(), err)
}
}
}
Expand All @@ -392,7 +392,7 @@ func (d *Datastore) CollectGarbage() error {
for _, m := range d.mounts {
if c, ok := m.Datastore.(ds.GCDatastore); ok {
if err := c.CollectGarbage(); err != nil {
return fmt.Errorf("gc on datastore at %s: %s", m.Prefix.String(), err.Error())
return xerrors.Errorf("gc on datastore at %s: %w", m.Prefix.String(), err)
}
}
}
Expand Down
42 changes: 0 additions & 42 deletions package.json

This file was deleted.

6 changes: 3 additions & 3 deletions retrystore/retrystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
package retrystore

import (
"fmt"
"time"

ds "github.com/ipfs/go-datastore"
xerrors "golang.org/x/xerrors"
)

// Datastore wraps a Batching datastore with a
Expand All @@ -23,7 +23,7 @@ type Datastore struct {
ds.Batching
}

var errFmtString = "ran out of retries trying to get past temporary error: %s"
var errFmtString = "ran out of retries trying to get past temporary error: %w"

func (d *Datastore) runOp(op func() error) error {
err := op()
Expand All @@ -40,7 +40,7 @@ func (d *Datastore) runOp(op func() error) error {
}
}

return fmt.Errorf(errFmtString, err)
return xerrors.Errorf(errFmtString, err)
}

// DiskUsage implements the PersistentDatastore interface.
Expand Down