mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-06 16:58:11 +08:00
debug(core, datastore, daemon) wrap errors
@jbenet @whyrusleeping @mappum very helpful for tracking down errors. the stack traces are only shown when debug mode is visible. They function best when caught at the source. I propose we use this errors package as a drop-in replacement for fmt.Errorf and errors.New in all of our code, and use errors.Wrap for external errors as they emerge from others' libraries. License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com> Signed-off-by: Brian Tiger Chow <brian.holderchow@gmail.com>
This commit is contained in:
parent
d0a3f9ba9a
commit
2bbfe4d56f
@ -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()
|
||||
|
||||
|
||||
16
core/core.go
16
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)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user