diff --git a/cmd/ipfs2/daemon.go b/cmd/ipfs2/daemon.go index ea73a9f25..71bd4b548 100644 --- a/cmd/ipfs2/daemon.go +++ b/cmd/ipfs2/daemon.go @@ -6,6 +6,7 @@ import ( ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net" + errors "github.com/jbenet/go-ipfs/util/errors" manners "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners" cmds "github.com/jbenet/go-ipfs/commands" @@ -35,7 +36,7 @@ the daemon. func daemonFunc(req cmds.Request) (interface{}, error) { lock, err := daemon.Lock(req.Context().ConfigRoot) if err != nil { - return nil, fmt.Errorf("Couldn't obtain lock. Is another daemon already running?") + return nil, errors.Errorf("Couldn't obtain lock. Is another daemon already running?") } defer lock.Close() diff --git a/core/core.go b/core/core.go index 4e2c5f89a..831692731 100644 --- a/core/core.go +++ b/core/core.go @@ -2,7 +2,6 @@ package core import ( "encoding/base64" - "errors" "fmt" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" @@ -15,6 +14,7 @@ import ( exchange "github.com/jbenet/go-ipfs/exchange" bitswap "github.com/jbenet/go-ipfs/exchange/bitswap" bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network" + mount "github.com/jbenet/go-ipfs/fuse/mount" merkledag "github.com/jbenet/go-ipfs/merkledag" namesys "github.com/jbenet/go-ipfs/namesys" inet "github.com/jbenet/go-ipfs/net" @@ -26,8 +26,8 @@ import ( routing "github.com/jbenet/go-ipfs/routing" dht "github.com/jbenet/go-ipfs/routing/dht" u "github.com/jbenet/go-ipfs/util" - mount "github.com/jbenet/go-ipfs/fuse/mount" ctxc "github.com/jbenet/go-ipfs/util/ctxcloser" + "github.com/jbenet/go-ipfs/util/errors" ) const IpnsValidatorTag = "ipns" @@ -102,7 +102,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { }() if cfg == nil { - return nil, fmt.Errorf("configuration required") + return nil, errors.Errorf("configuration required") } // derive this from a higher context. @@ -115,14 +115,14 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { // setup datastore. if n.Datastore, err = makeDatastore(cfg.Datastore); err != nil { - return nil, err + return nil, errors.Wrap(err) } // setup peerstore + local peer identity n.Peerstore = peer.NewPeerstore() n.Identity, err = initIdentity(&n.Config.Identity, n.Peerstore, online) if err != nil { - return nil, err + return nil, errors.Wrap(err) } // setup online services @@ -142,12 +142,12 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { // setup the network listenAddrs, err := listenAddresses(cfg) if err != nil { - return nil, err + return nil, errors.Wrap(err) } n.Network, err = inet.NewIpfsNetwork(ctx, listenAddrs, n.Identity, n.Peerstore, muxMap) if err != nil { - return nil, err + return nil, errors.Wrap(err) } n.AddCloserChild(n.Network) @@ -176,7 +176,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { // session that simply doesn't return blocks n.Blocks, err = bserv.NewBlockService(n.Datastore, n.Exchange) if err != nil { - return nil, err + return nil, errors.Wrap(err) } n.DAG = merkledag.NewDAGService(n.Blocks) diff --git a/core/datastore.go b/core/datastore.go index 0611939ae..26f44e5d5 100644 --- a/core/datastore.go +++ b/core/datastore.go @@ -1,8 +1,6 @@ package core import ( - "fmt" - ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" fsds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/fs" ktds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/keytransform" @@ -12,11 +10,12 @@ import ( config "github.com/jbenet/go-ipfs/config" u "github.com/jbenet/go-ipfs/util" + "github.com/jbenet/go-ipfs/util/errors" ) func makeDatastore(cfg config.Datastore) (u.ThreadSafeDatastoreCloser, error) { if len(cfg.Type) == 0 { - return nil, fmt.Errorf("config datastore.type required") + return nil, errors.Errorf("config datastore.type required") } switch cfg.Type { @@ -36,16 +35,17 @@ func makeDatastore(cfg config.Datastore) (u.ThreadSafeDatastoreCloser, error) { return u.CloserWrap(syncds.MutexWrap(ktd)), nil } - return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type) + return nil, errors.Errorf("Unknown datastore type: %s", cfg.Type) } func makeLevelDBDatastore(cfg config.Datastore) (u.ThreadSafeDatastoreCloser, error) { if len(cfg.Path) == 0 { - return nil, fmt.Errorf("config datastore.path required for leveldb") + return nil, errors.Errorf("config datastore.path required for leveldb") } - return lds.NewDatastore(cfg.Path, &lds.Options{ + ds, err := lds.NewDatastore(cfg.Path, &lds.Options{ // TODO don't import ldbopts. Get from go-datastore.leveldb Compression: ldbopts.NoCompression, }) + return ds, errors.Wrap(err) } diff --git a/daemon2/daemon.go b/daemon2/daemon.go index 04aade68c..d8fb3d43f 100644 --- a/daemon2/daemon.go +++ b/daemon2/daemon.go @@ -6,13 +6,15 @@ import ( lock "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock" "github.com/jbenet/go-ipfs/util" + "github.com/jbenet/go-ipfs/util/errors" ) // LockFile is the filename of the daemon lock, relative to config dir const LockFile = "daemon.lock" func Lock(confdir string) (io.Closer, error) { - return lock.Lock(path.Join(confdir, LockFile)) + c, err := lock.Lock(path.Join(confdir, LockFile)) + return c, errors.Wrap(err) } func Locked(confdir string) bool {