Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed Oct 3, 2016
1 parent 082eb6e commit a38e5cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

manet "gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
loggables "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables"
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
Expand Down Expand Up @@ -590,18 +591,28 @@ func profileIfEnabled() (func(), error) {
return func() {}, nil
}

var apiFileErrorFmt string = `Failed to parse %[1]s/api file.
var apiFileErrorFmt string = `Failed to parse '%[1]s/api' file.
error: %[2]s
If there is no daemon running, it is safe to delete it.
You can do it with:
ps aux | grep ipfs # check there is no ipfs daemon
rm %[1]s/api
If you're sure go-ipfs isn't running, you can just delete it.
Otherwise check:
`
var checkIPFSUnixFmt = "\tps aux | grep ipfs"
var checkIPFSWinFmt = "\ttasklist | findstr ipfs"

// getApiClient checks the repo, and the given options, checking for
// a running API service. if there is one, it returns a client.
// otherwise, it returns errApiNotRunning, or another error.
func getApiClient(repoPath, apiAddrStr string) (cmdsHttp.Client, error) {
var apiErrorFmt string
switch {
case osh.IsUnix():
apiErrorFmt = apiFileErrorFmt + checkIPFSUnixFmt
case osh.IsWindows():
apiErrorFmt = apiFileErrorFmt + checkIPFSWinFmt
default:
apiErrorFmt = apiFileErrorFmt
}

var addr ma.Multiaddr
var err error
if len(apiAddrStr) != 0 {
Expand All @@ -616,11 +627,11 @@ func getApiClient(repoPath, apiAddrStr string) (cmdsHttp.Client, error) {
}

if err != nil {
return nil, fmt.Errorf(apiFileErrorFmt, repoPath, err.Error())
return nil, fmt.Errorf(apiErrorFmt, repoPath, err.Error())
}
}
if len(addr.Protocols()) == 0 {
return nil, fmt.Errorf(apiFileErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
return nil, fmt.Errorf(apiErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
}

return apiClientForAddr(addr)
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@
"author": "whyrusleeping",
"hash": "QmdCL8M8DXJdSRnwhpDhukX5r8ydjxnzPJpaKrFudDA8yn",
"name": "hang-fds",
"version": "0.0.0"
},
{
"author": "Kubuxu",
"hash": "QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93",
"name": "go-os-helper",
"version": "0.0.0"
}
],
Expand Down

0 comments on commit a38e5cd

Please sign in to comment.