Skip to content

Commit a38e5cd

Browse files
committed
improve error messages
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 082eb6e commit a38e5cd

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cmd/ipfs/main.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
manet "gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net"
3030
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
31+
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
3132
loggables "gx/ipfs/QmYrv4LgCC8FhG2Ab4bwuq5DqBdwMtx3hMb3KKJDZcr2d7/go-libp2p-loggables"
3233
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
3334
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
@@ -590,18 +591,28 @@ func profileIfEnabled() (func(), error) {
590591
return func() {}, nil
591592
}
592593

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

601602
// getApiClient checks the repo, and the given options, checking for
602603
// a running API service. if there is one, it returns a client.
603604
// otherwise, it returns errApiNotRunning, or another error.
604605
func getApiClient(repoPath, apiAddrStr string) (cmdsHttp.Client, error) {
606+
var apiErrorFmt string
607+
switch {
608+
case osh.IsUnix():
609+
apiErrorFmt = apiFileErrorFmt + checkIPFSUnixFmt
610+
case osh.IsWindows():
611+
apiErrorFmt = apiFileErrorFmt + checkIPFSWinFmt
612+
default:
613+
apiErrorFmt = apiFileErrorFmt
614+
}
615+
605616
var addr ma.Multiaddr
606617
var err error
607618
if len(apiAddrStr) != 0 {
@@ -616,11 +627,11 @@ func getApiClient(repoPath, apiAddrStr string) (cmdsHttp.Client, error) {
616627
}
617628

618629
if err != nil {
619-
return nil, fmt.Errorf(apiFileErrorFmt, repoPath, err.Error())
630+
return nil, fmt.Errorf(apiErrorFmt, repoPath, err.Error())
620631
}
621632
}
622633
if len(addr.Protocols()) == 0 {
623-
return nil, fmt.Errorf(apiFileErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
634+
return nil, fmt.Errorf(apiErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
624635
}
625636

626637
return apiClientForAddr(addr)

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@
262262
"author": "whyrusleeping",
263263
"hash": "QmdCL8M8DXJdSRnwhpDhukX5r8ydjxnzPJpaKrFudDA8yn",
264264
"name": "hang-fds",
265+
"version": "0.0.0"
266+
},
267+
{
268+
"author": "Kubuxu",
269+
"hash": "QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93",
270+
"name": "go-os-helper",
265271
"version": "0.0.0"
266272
}
267273
],

0 commit comments

Comments
 (0)