ipfs/kubo · error

cannot convert to CIDv0 with any codec other than dag-pb

Error message

cannot convert to CIDv0 with any codec other than dag-pb

What it means

`ipfs cid base32`/`cid format` with --cid-ver=0 (or version option '0') refuses conversion to CIDv0 when a different codec was requested. CIDv0 is by definition dag-pb with the implicit raw multihash, so any other codec cannot be represented as v0.

Source

Thrown at core/commands/cid.go:95

		opts.fmtStr = fmtStr

		if codecStr != "" {
			var codec mc.Code
			err := codec.Set(codecStr)
			if err != nil {
				return err
			}
			opts.newCodec = uint64(codec)
		} // otherwise, leave it as 0 (not a valid IPLD codec)

		switch verStr {
		case "":
			if baseStr != "" {
				opts.verConv = toCidV1
			}
		case "0":
			if opts.newCodec != 0 && opts.newCodec != cid.DagProtobuf {
				return errors.New("cannot convert to CIDv0 with any codec other than dag-pb")
			}
			if baseStr != "" && baseStr != "base58btc" {
				return errors.New("cannot convert to CIDv0 with any multibase other than the implicit base58btc")
			}
			opts.verConv = toCidV0
		case "1":
			opts.verConv = toCidV1
		default:
			return fmt.Errorf("invalid cid version: %q", verStr)
		}

		if baseStr != "" {
			encoder, err := mbase.EncoderByName(baseStr)
			if err != nil {
				return err
			}
			opts.newBase = encoder.Encoding()
		} else {

View on GitHub (pinned to 329838acdf)

Solutions

  1. Keep dag-pb codec (or omit --cid-codec) when converting to CIDv0
  2. Use --cid-ver=1 if you need a non-dag-pb codec
  3. Drop the codec option entirely and only pass --cid-ver=0

Example fix

// before
ipfs cid format --cid-codec=raw --cid-ver=0 <cid>
// after
ipfs cid format --cid-codec=dag-pb --cid-ver=0 <cid>
Defensive patterns

Strategy: validation

Validate before calling

if ver == 0 && codec != "" && codec != "dag-pb" {
    return fmt.Errorf("codec %s incompatible with CIDv0", codec)
}

Try / catch

if err := cmd.Run(); err != nil {
    if strings.Contains(err.Error(), "codec other than dag-pb") {
        // fall back to CIDv1
    }
}

Prevention

When it happens

Trigger: Running `ipfs cid format --cid-codec=raw --cid-ver=0 <cid>` or setting the codec option to any non-empty value other than dag-pb (codec 0x70) while requesting version 0.

Common situations: Converting raw/identity or dag-cbor CIDs down to v0 for legacy compatibility; scripts forcing --cid-ver=0 while also passing --cid-codec.

Related errors


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