@@ -7,15 +7,14 @@ import (
77)
88
99func stringToBytes (s string ) ([]byte , error ) {
10-
1110 // consume trailing slashes
1211 s = strings .TrimRight (s , "/" )
1312
1413 var b bytes.Buffer
1514 sp := strings .Split (s , "/" )
1615
1716 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 )
1918 }
2019
2120 // consume first empty elem
@@ -25,7 +24,7 @@ func stringToBytes(s string) ([]byte, error) {
2524 name := sp [0 ]
2625 p := ProtocolWithName (name )
2726 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 ])
2928 }
3029 _ , _ = b .Write (CodeToVarint (p .Code ))
3130 sp = sp [1 :]
@@ -35,7 +34,7 @@ func stringToBytes(s string) ([]byte, error) {
3534 }
3635
3736 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 )
3938 }
4039
4140 if p .Path {
@@ -46,7 +45,7 @@ func stringToBytes(s string) ([]byte, error) {
4645
4746 a , err := p .Transcoder .StringToBytes (sp [0 ])
4847 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 )
5049 }
5150 if p .Size < 0 { // varint size.
5251 _ , _ = b .Write (CodeToVarint (len (a )))
0 commit comments