提交 deb7af02 作者: Steven Allen

feat: improve errors when a path fails to parse

This helps with issues like #4190 by telling the user the path that failed to
parse.

fixes #4190
上级 f72be19a
......@@ -51,7 +51,7 @@ require (
github.com/ipfs/go-metrics-interface v0.0.1
github.com/ipfs/go-metrics-prometheus v0.0.2
github.com/ipfs/go-mfs v0.0.7
github.com/ipfs/go-path v0.0.3
github.com/ipfs/go-path v0.0.4
github.com/ipfs/go-unixfs v0.0.5
github.com/ipfs/go-verifcid v0.0.1
github.com/ipfs/hang-fds v0.0.1
......@@ -63,14 +63,14 @@ require (
github.com/jbenet/go-random-files v0.0.0-20190219210431-31b3f20ebded
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-libp2p v0.0.23
github.com/libp2p/go-libp2p v0.0.24
github.com/libp2p/go-libp2p-autonat-svc v0.0.5
github.com/libp2p/go-libp2p-circuit v0.0.6
github.com/libp2p/go-libp2p-connmgr v0.0.4
github.com/libp2p/go-libp2p-crypto v0.0.2
github.com/libp2p/go-libp2p-host v0.0.3
github.com/libp2p/go-libp2p-interface-connmgr v0.0.4
github.com/libp2p/go-libp2p-kad-dht v0.0.10
github.com/libp2p/go-libp2p-kad-dht v0.0.11
github.com/libp2p/go-libp2p-kbucket v0.1.1
github.com/libp2p/go-libp2p-loggables v0.0.1
github.com/libp2p/go-libp2p-metrics v0.0.1
......@@ -97,7 +97,7 @@ require (
github.com/miekg/dns v1.1.8 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mr-tron/base58 v1.1.2
github.com/multiformats/go-multiaddr v0.0.2
github.com/multiformats/go-multiaddr v0.0.3
github.com/multiformats/go-multiaddr-dns v0.0.2
github.com/multiformats/go-multiaddr-net v0.0.1
github.com/multiformats/go-multibase v0.0.1
......@@ -124,7 +124,6 @@ require (
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20190426135247-a129542de9ae
golang.org/x/text v0.3.2 // indirect
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28
gotest.tools/gotestsum v0.3.4
)
......
......@@ -3,6 +3,7 @@ package resolve
import (
"context"
"errors"
"fmt"
"strings"
"github.com/ipfs/go-ipld-format"
......@@ -36,8 +37,9 @@ func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (pat
seg := p.Segments()
if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
evt.Append(logging.LoggableMap{"error": path.ErrNoComponents.Error()})
return "", path.ErrNoComponents
err := fmt.Errorf("invalid path %q: ipns path missing IPNS ID", p)
evt.Append(logging.LoggableMap{"error": err})
return "", err
}
extensions := seg[2:]
......
......@@ -129,7 +129,7 @@ test_get_cmd() {
'
test_expect_success "ipfs get ../.. should fail" '
echo "Error: invalid 'ipfs ref' path" >expected &&
echo "Error: invalid path \"../..\": selected encoding not supported" >expected &&
test_must_fail ipfs get ../.. 2>actual &&
test_cmp expected actual
'
......
......@@ -187,7 +187,7 @@ done
# This one is different. `local` will be interpreted as a path if the command isn't defined.
test_expect_success "test gateway api is sanitized: refs/local" '
echo "Error: invalid '"'ipfs ref'"' path" > refs_local_expected &&
echo "Error: invalid path \"local\": selected encoding not supported" > refs_local_expected &&
! ipfs --api /ip4/127.0.0.1/tcp/$port refs local > refs_local_actual 2>&1 &&
test_cmp refs_local_expected refs_local_actual
'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论