Skip to content

Commit 0c0363a

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

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

cmd/ipfs/main.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ import (
3232
repo "github.com/ipfs/go-ipfs/repo"
3333
config "github.com/ipfs/go-ipfs/repo/config"
3434
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
35+
3536
loggables "gx/ipfs/QmTMy4hVSY28DdwJ9kBz6y7q6MuioFzPcpM3Ma3aPjo1i3/go-libp2p-loggables"
37+
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
3638
)
3739

3840
// log is the command logger
@@ -591,18 +593,28 @@ func profileIfEnabled() (func(), error) {
591593
return func() {}, nil
592594
}
593595

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

602604
// getApiClient checks the repo, and the given options, checking for
603605
// a running API service. if there is one, it returns a client.
604606
// otherwise, it returns errApiNotRunning, or another error.
605607
func getApiClient(repoPath, apiAddrStr string) (cmdsHttp.Client, error) {
608+
var apiErrorFmt string
609+
switch {
610+
case osh.IsUnix():
611+
apiErrorFmt = apiFileErrorFmt + checkIPFSUnixFmt
612+
case osh.IsWindows():
613+
apiErrorFmt = apiFileErrorFmt + checkIPFSWinFmt
614+
default:
615+
apiErrorFmt = apiFileErrorFmt
616+
}
617+
606618
var addr ma.Multiaddr
607619
var err error
608620
if len(apiAddrStr) != 0 {
@@ -617,11 +629,11 @@ func getApiClient(repoPath, apiAddrStr string) (cmdsHttp.Client, error) {
617629
}
618630

619631
if err != nil {
620-
return nil, fmt.Errorf(apiFileErrorFmt, repoPath, err.Error())
632+
return nil, fmt.Errorf(apiErrorFmt, repoPath, err.Error())
621633
}
622634
}
623635
if len(addr.Protocols()) == 0 {
624-
return nil, fmt.Errorf(apiFileErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
636+
return nil, fmt.Errorf(apiErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
625637
}
626638

627639
return apiClientForAddr(addr)

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@
281281
"hash": "QmRcAVqrbY5wryx7hfNLtiUZbCcstzaJL7YJFBboitcqWF",
282282
"name": "go-ipld-cbor",
283283
"version": "0.3.0"
284+
},
285+
{
286+
"author": "Kubuxu",
287+
"hash": "QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93",
288+
"name": "go-os-helper",
289+
"version": "0.0.0"
284290
}
285291
],
286292
"gxVersion": "0.4.0",

0 commit comments

Comments
 (0)