From ef65bb1ce3431dc44e6273b2936c0b6f1d3cb62f Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow <brian.holderchow@gmail.com> Date: Mon, 17 Nov 2014 01:43:25 -0800 Subject: [PATCH] revert to debug error @jbenet License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com> --- cmd/ipfs2/daemon.go | 6 +++--- cmd/ipfs2/init.go | 18 +++++++++--------- cmd/ipfs2/main.go | 5 +++-- config/config.go | 4 ++-- core/core.go | 18 +++++++++--------- core/datastore.go | 10 +++++----- daemon2/daemon.go | 4 ++-- util/{errors => debugerror}/debug.go | 4 ++-- 8 files changed, 35 insertions(+), 34 deletions(-) rename util/{errors => debugerror}/debug.go (85%) diff --git a/cmd/ipfs2/daemon.go b/cmd/ipfs2/daemon.go index 8ec23de15..32eeb5f58 100644 --- a/cmd/ipfs2/daemon.go +++ b/cmd/ipfs2/daemon.go @@ -13,7 +13,7 @@ import ( commands "github.com/jbenet/go-ipfs/core/commands2" daemon "github.com/jbenet/go-ipfs/daemon2" util "github.com/jbenet/go-ipfs/util" - errors "github.com/jbenet/go-ipfs/util/errors" + "github.com/jbenet/go-ipfs/util/debugerror" ) const ( @@ -54,14 +54,14 @@ func daemonFunc(req cmds.Request) (interface{}, error) { if !util.FileExists(req.Context().ConfigRoot) { err := initWithDefaults(req.Context().ConfigRoot) if err != nil { - return nil, errors.Wrap(err) + return nil, debugerror.Wrap(err) } } } lock, err := daemon.Lock(req.Context().ConfigRoot) if err != nil { - return nil, errors.Errorf("Couldn't obtain lock. Is another daemon already running?") + return nil, debugerror.Errorf("Couldn't obtain lock. Is another daemon already running?") } defer lock.Close() diff --git a/cmd/ipfs2/init.go b/cmd/ipfs2/init.go index 3c8670d4c..c35198f1d 100644 --- a/cmd/ipfs2/init.go +++ b/cmd/ipfs2/init.go @@ -16,7 +16,7 @@ import ( chunk "github.com/jbenet/go-ipfs/importer/chunk" peer "github.com/jbenet/go-ipfs/peer" u "github.com/jbenet/go-ipfs/util" - errors "github.com/jbenet/go-ipfs/util/errors" + "github.com/jbenet/go-ipfs/util/debugerror" ) const nBitsForKeypairDefault = 4096 @@ -62,7 +62,7 @@ var initCmd = &cmds.Command{ }, } -var errCannotInitConfigExists = errors.New(`ipfs configuration file already exists! +var errCannotInitConfigExists = debugerror.New(`ipfs configuration file already exists! Reinitializing would overwrite your keys. (use -f to force overwrite) `) @@ -84,7 +84,7 @@ For a short demo of what you can do, enter 'ipfs tour' func initWithDefaults(configRoot string) error { _, err := doInit(configRoot, "", false, nBitsForKeypairDefault) - return errors.Wrap(err) + return debugerror.Wrap(err) } func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypair int) (interface{}, error) { @@ -93,7 +93,7 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai configFilename, err := config.Filename(configRoot) if err != nil { - return nil, errors.New("Couldn't get home directory path") + return nil, debugerror.New("Couldn't get home directory path") } if u.FileExists(configFilename) && !force { @@ -155,7 +155,7 @@ func datastoreConfig(dspath string) (config.Datastore, error) { err := initCheckDir(dspath) if err != nil { - return ds, errors.Errorf("datastore: %s", err) + return ds, debugerror.Errorf("datastore: %s", err) } return ds, nil @@ -229,7 +229,7 @@ func identityConfig(nbits int, onBegin func(), onSuccess func(config.Identity)) // TODO guard higher up ident := config.Identity{} if nbits < 1024 { - return ident, errors.New("Bitsize less than 1024 is considered unsafe.") + return ident, debugerror.New("Bitsize less than 1024 is considered unsafe.") } onBegin() @@ -260,13 +260,13 @@ func initLogs(logpath string) (config.Logs, error) { var err error logpath, err = config.LogsPath("") if err != nil { - return config.Logs{}, errors.Wrap(err) + return config.Logs{}, debugerror.Wrap(err) } } err := initCheckDir(logpath) if err != nil { - return config.Logs{}, errors.Errorf("logs: %s", err) + return config.Logs{}, debugerror.Errorf("logs: %s", err) } return config.Logs{ @@ -285,7 +285,7 @@ func initCheckDir(path string) error { if f, err := os.Create(filepath.Join(path, "._check_writeable")); err == nil { os.Remove(f.Name()) } else { - return errors.New("'" + path + "' is not writeable") + return debugerror.New("'" + path + "' is not writeable") } return nil } diff --git a/cmd/ipfs2/main.go b/cmd/ipfs2/main.go index 6ea454c43..01b2d133f 100644 --- a/cmd/ipfs2/main.go +++ b/cmd/ipfs2/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -21,7 +22,7 @@ import ( daemon "github.com/jbenet/go-ipfs/daemon2" updates "github.com/jbenet/go-ipfs/updates" u "github.com/jbenet/go-ipfs/util" - errors "github.com/jbenet/go-ipfs/util/errors" + "github.com/jbenet/go-ipfs/util/debugerror" eventlog "github.com/jbenet/go-ipfs/util/eventlog" ) @@ -331,7 +332,7 @@ func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) { var found bool cmd, found = cmd.Subcommands[cmp] if !found { - return nil, errors.Errorf("subcommand %s should be in root", cmp) + return nil, debugerror.Errorf("subcommand %s should be in root", cmp) } if cmdDetails, found := cmdDetailsMap[cmd]; found { diff --git a/config/config.go b/config/config.go index ed53509dc..73b2bc707 100644 --- a/config/config.go +++ b/config/config.go @@ -9,7 +9,7 @@ import ( "path/filepath" u "github.com/jbenet/go-ipfs/util" - errors "github.com/jbenet/go-ipfs/util/errors" + "github.com/jbenet/go-ipfs/util/debugerror" ) var log = u.Logger("config") @@ -147,7 +147,7 @@ func (i *Identity) DecodePrivateKey(passphrase string) (crypto.PrivateKey, error func Load(filename string) (*Config, error) { // if nothing is there, fail. User must run 'ipfs init' if _, err := os.Stat(filename); os.IsNotExist(err) { - return nil, errors.New("ipfs not initialized, please run 'ipfs init'") + return nil, debugerror.New("ipfs not initialized, please run 'ipfs init'") } var cfg Config diff --git a/core/core.go b/core/core.go index 831692731..b8133377b 100644 --- a/core/core.go +++ b/core/core.go @@ -27,7 +27,7 @@ import ( dht "github.com/jbenet/go-ipfs/routing/dht" u "github.com/jbenet/go-ipfs/util" ctxc "github.com/jbenet/go-ipfs/util/ctxcloser" - "github.com/jbenet/go-ipfs/util/errors" + "github.com/jbenet/go-ipfs/util/debugerror" ) const IpnsValidatorTag = "ipns" @@ -102,7 +102,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { }() if cfg == nil { - return nil, errors.Errorf("configuration required") + return nil, debugerror.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, errors.Wrap(err) + return nil, debugerror.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, errors.Wrap(err) + return nil, debugerror.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, errors.Wrap(err) + return nil, debugerror.Wrap(err) } n.Network, err = inet.NewIpfsNetwork(ctx, listenAddrs, n.Identity, n.Peerstore, muxMap) if err != nil { - return nil, errors.Wrap(err) + return nil, debugerror.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, errors.Wrap(err) + return nil, debugerror.Wrap(err) } n.DAG = merkledag.NewDAGService(n.Blocks) @@ -202,11 +202,11 @@ func (n *IpfsNode) OnlineMode() bool { func initIdentity(cfg *config.Identity, peers peer.Peerstore, online bool) (peer.Peer, error) { if cfg.PeerID == "" { - return nil, errors.New("Identity was not set in config (was ipfs init run?)") + return nil, debugerror.New("Identity was not set in config (was ipfs init run?)") } if len(cfg.PeerID) == 0 { - return nil, errors.New("No peer ID in config! (was ipfs init run?)") + return nil, debugerror.New("No peer ID in config! (was ipfs init run?)") } // get peer from peerstore (so it is constructed there) diff --git a/core/datastore.go b/core/datastore.go index 26f44e5d5..3bca8ec0e 100644 --- a/core/datastore.go +++ b/core/datastore.go @@ -10,12 +10,12 @@ import ( config "github.com/jbenet/go-ipfs/config" u "github.com/jbenet/go-ipfs/util" - "github.com/jbenet/go-ipfs/util/errors" + "github.com/jbenet/go-ipfs/util/debugerror" ) func makeDatastore(cfg config.Datastore) (u.ThreadSafeDatastoreCloser, error) { if len(cfg.Type) == 0 { - return nil, errors.Errorf("config datastore.type required") + return nil, debugerror.Errorf("config datastore.type required") } switch cfg.Type { @@ -35,17 +35,17 @@ func makeDatastore(cfg config.Datastore) (u.ThreadSafeDatastoreCloser, error) { return u.CloserWrap(syncds.MutexWrap(ktd)), nil } - return nil, errors.Errorf("Unknown datastore type: %s", cfg.Type) + return nil, debugerror.Errorf("Unknown datastore type: %s", cfg.Type) } func makeLevelDBDatastore(cfg config.Datastore) (u.ThreadSafeDatastoreCloser, error) { if len(cfg.Path) == 0 { - return nil, errors.Errorf("config datastore.path required for leveldb") + return nil, debugerror.Errorf("config datastore.path required for leveldb") } 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) + return ds, debugerror.Wrap(err) } diff --git a/daemon2/daemon.go b/daemon2/daemon.go index d8fb3d43f..f1c25fc7b 100644 --- a/daemon2/daemon.go +++ b/daemon2/daemon.go @@ -6,7 +6,7 @@ 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" + "github.com/jbenet/go-ipfs/util/debugerror" ) // LockFile is the filename of the daemon lock, relative to config dir @@ -14,7 +14,7 @@ const LockFile = "daemon.lock" func Lock(confdir string) (io.Closer, error) { c, err := lock.Lock(path.Join(confdir, LockFile)) - return c, errors.Wrap(err) + return c, debugerror.Wrap(err) } func Locked(confdir string) bool { diff --git a/util/errors/debug.go b/util/debugerror/debug.go similarity index 85% rename from util/errors/debug.go rename to util/debugerror/debug.go index 176d33b11..eb91b775f 100644 --- a/util/errors/debug.go +++ b/util/debugerror/debug.go @@ -1,6 +1,6 @@ -// package errors provides ways to augment errors with additional +// package debugerror provides ways to augment errors with additional // information to allow for easier debugging. -package errors +package debugerror import ( "errors" -- GitLab