@@ -7,15 +7,14 @@ import (
7
7
)
8
8
9
9
func stringToBytes (s string ) ([]byte , error ) {
10
-
11
10
// consume trailing slashes
12
11
s = strings .TrimRight (s , "/" )
13
12
14
13
var b bytes.Buffer
15
14
sp := strings .Split (s , "/" )
16
15
17
16
if sp [0 ] != "" {
18
- return nil , fmt .Errorf ("invalid multiaddr, must begin with /" )
17
+ return nil , fmt .Errorf ("failed to parse multiaddr %q: must begin with /" , s )
19
18
}
20
19
21
20
// consume first empty elem
@@ -25,7 +24,7 @@ func stringToBytes(s string) ([]byte, error) {
25
24
name := sp [0 ]
26
25
p := ProtocolWithName (name )
27
26
if p .Code == 0 {
28
- return nil , fmt .Errorf ("no protocol with name %s" , sp [0 ])
27
+ return nil , fmt .Errorf ("failed to parse multiaddr %q: unknown protocol %s" , s , sp [0 ])
29
28
}
30
29
_ , _ = b .Write (CodeToVarint (p .Code ))
31
30
sp = sp [1 :]
@@ -35,7 +34,7 @@ func stringToBytes(s string) ([]byte, error) {
35
34
}
36
35
37
36
if len (sp ) < 1 {
38
- return nil , fmt .Errorf ("protocol requires address, none given: %s " , name )
37
+ return nil , fmt .Errorf ("failed to parse multiaddr %q: unexpected end of multiaddr " , s )
39
38
}
40
39
41
40
if p .Path {
@@ -46,7 +45,7 @@ func stringToBytes(s string) ([]byte, error) {
46
45
47
46
a , err := p .Transcoder .StringToBytes (sp [0 ])
48
47
if err != nil {
49
- return nil , fmt .Errorf ("failed to parse %s: %s %s" , p . Name , sp [0 ], err )
48
+ return nil , fmt .Errorf ("failed to parse multiaddr %q: invalid value %q for protocol %s: %s" , s , sp [0 ], p . Name , err )
50
49
}
51
50
if p .Size < 0 { // varint size.
52
51
_ , _ = b .Write (CodeToVarint (len (a )))
0 commit comments