Skip to content

Commit

Permalink
util/ipfsaddr: recover from panics parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenet committed Feb 1, 2015
1 parent eee8715 commit 88ee455
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions util/ipfsaddr/ipfsaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"

peer "github.com/jbenet/go-ipfs/p2p/peer"
eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
)

var log = eventlog.Logger("ipfsaddr")

// ErrInvalidAddr signals an address is not a valid ipfs address.
var ErrInvalidAddr = errors.New("invalid ipfs address")

Expand Down Expand Up @@ -62,13 +65,14 @@ func ParseString(str string) (a IPFSAddr, err error) {

// ParseMultiaddr parses a multiaddr into an IPFSAddr
func ParseMultiaddr(m ma.Multiaddr) (a IPFSAddr, err error) {
// // never panic.
// defer func() {
// if r := recover(); r != nil {
// a = nil
// err = ErrInvalidAddr
// }
// }()
// never panic.
defer func() {
if r := recover(); r != nil {
log.Debug("recovered from panic: ", r)
a = nil
err = ErrInvalidAddr
}
}()

if m == nil {
return nil, ErrInvalidAddr
Expand Down

0 comments on commit 88ee455

Please sign in to comment.