From 043eed1b7bfb2d4068fd5eb380de9b0961f29ea0 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 27 Apr 2022 17:11:38 +0200 Subject: [PATCH] fix: CIDv1 error with go-libp2p 0.19 (#32) The error message changed in libp2p and we no longer get this nice error message. String matching is a bad practice so just removing it, as we validate CID and codec already. This commit was moved from ipfs/go-namesys@605965e675aa7758ef32c4b5cd8ae856738fe77c --- namesys/namesys.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/namesys/namesys.go b/namesys/namesys.go index 51b5e7096..6dfad0b71 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -202,12 +202,12 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. // CIDs in IPNS are expected to have libp2p-key multicodec // We ease the transition by returning a more meaningful error with a valid CID - if err != nil && err.Error() == "can't convert CID of type protobuf to a peer ID" { + if err != nil { ipnsCid, cidErr := cid.Decode(key) if cidErr == nil && ipnsCid.Version() == 1 && ipnsCid.Type() != cid.Libp2pKey { fixedCid := cid.NewCidV1(cid.Libp2pKey, ipnsCid.Hash()).String() codecErr := fmt.Errorf("peer ID represented as CIDv1 require libp2p-key multicodec: retry with /ipns/%s", fixedCid) - log.Debugf("RoutingResolver: could not convert public key hash %s to peer ID: %s\n", key, codecErr) + log.Debugf("RoutingResolver: could not convert public key hash %q to peer ID: %s\n", key, codecErr) out <- onceResult{err: codecErr} close(out) return out