ipfs/kubo · error

can't convert non-dag-pb nodes to cidv0

Error message

can't convert non-dag-pb nodes to cidv0

What it means

toCidV0 performs the actual CID-to-v0 conversion after option validation and re-checks the codec: only dag-pb (0x70) nodes can be CIDv0. This fires when the new codec was not set via options (so the earlier guard was skipped) but the source CID itself carries a non-dag-pb codec.

Source

Thrown at core/commands/cid.go:256

			res.ErrorMsg = err.Error()
		} else {
			res.Formatted = str
		}
		emitErr = resp.Emit(res)
	}
	if emitErr != nil {
		return emitErr
	}
	err := itr.err()
	if err != nil {
		return err
	}
	return nil
}

func toCidV0(c cid.Cid) (cid.Cid, error) {
	if c.Type() != cid.DagProtobuf {
		return cid.Cid{}, fmt.Errorf("can't convert non-dag-pb nodes to cidv0")
	}
	return cid.NewCidV0(c.Hash()), nil
}

func toCidV1(c cid.Cid) (cid.Cid, error) {
	return cid.NewCidV1(c.Type(), c.Hash()), nil
}

type CodeAndName struct {
	Code int
	Name string
}

const (
	prefixOptionName  = "prefix"
	numericOptionName = "numeric"
)

View on GitHub (pinned to 329838acdf)

Solutions

  1. Convert to CIDv1 instead: ipfs cid format --cid-ver=1 <cid>
  2. Re-add the content as dag-pb (e.g. `ipfs add --cid-version 0`) to get a v0 CID
  3. Use `ipfs dag put` with codec dag-pb before attempting v0 conversion

Example fix

// before
ipfs cid format --cid-ver=0 bafkrei...  // raw codec
// after
ipfs cid format --cid-ver=1 bafkrei...
Defensive patterns

Strategy: validation

Validate before calling

parsed, err := cid.Decode(cidStr)
if err == nil && parsed.Type() != cid.DagProtobuf {
    // do not request CIDv0
}

Try / catch

if err != nil && strings.Contains(err.Error(), "non-dag-pb") {
    v1, _ := cid.CidFromHexString(cidStr)
    v1c := cid.NewCidV1(v1.Type(), v1.Hash())
    _ = v1c
}

Prevention

When it happens

Trigger: `ipfs cid format --cid-ver=0 <raw-or-dag-cbor-cid>` where the input CID's own codec is not dag-pb; converting an identity/raw coded CID to v0.

Common situations: Assuming a raw block CID can be 'downgraded' to v0; legacy tooling that expects all CIDs to be v0-convertible; converting multihash-only via c.Hash() from non-dag-pb inputs.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/d776945980f140f9. Report an issue: GitHub.