ipfs/kubo · error
invalid encoding: %s - %s
Error message
invalid encoding: %s - %s
What it means
`ipfs dag get` re-encodes the fetched IPLD node using the multicodec named by the node's CID (or --output-codec). Before encoding, kubo looks up a registered encoder for that codec with multicodec.LookupEncoder. If no encoder is registered for the codec, the command fails with this wrapped error showing the codec name/number and the underlying lookup error.
Source
Thrown at core/commands/dag/get.go:67
universal, ok := obj.(ipldlegacy.UniversalNode)
if !ok {
return fmt.Errorf("%T is not a valid IPLD node", obj)
}
finalNode := universal.(ipld.Node)
if len(remainder) > 0 {
remainderPath := ipld.ParsePath(path.SegmentsToString(remainder...))
finalNode, err = traversal.Get(finalNode, remainderPath)
if err != nil {
return err
}
}
encoder, err := multicodec.LookupEncoder(uint64(codec))
if err != nil {
return fmt.Errorf("invalid encoding: %s - %s", codec, err)
}
r, w := io.Pipe()
go func() {
defer w.Close()
// Encoding runs the codec named by the node's CID, so it runs
// third-party code. This goroutine is detached from the request, and a
// panic on it would end the daemon rather than the command.
defer func() {
if rec := recover(); rec != nil {
log.Errorf("recovered from panic encoding %s as %s: %v\n%s", p, codec, rec, debug.Stack())
_ = w.CloseWithError(errors.New("internal error encoding node"))
}
}()
if err := encoder(finalNode, w); err != nil {
_ = w.CloseWithError(err)
}
}()View on GitHub (pinned to 329838acdf)
Solutions
- Use a supported codec: dag-cbor, dag-json, dag-pb, or raw
- Check the CID's codec with `ipfs dag stat` or `ipfs cid format -f %z` and fetch with a codec kubo can encode
- Upgrade kubo if the codec was added in a newer multicodec table
- Register the codec via a kubo plugin if it is a custom codec
Example fix
// before ipfs dag get --output-codec=cty bafy... // error: invalid encoding: cty - no encoder found // after ipfs dag get --output-codec=dag-json bafy...
Defensive patterns
Strategy: validation
Validate before calling
// Check the CID's codec before calling dag get
parts := strings.SplitN(cidStr, "/", 2)
c, err := cid.Decode(parts[0])
if err != nil { return err }
switch c.Type() {
case cid.DagProtobuf, cid.DagCBOR, cid.DagJSON, cid.Raw:
// supported
default:
return fmt.Errorf("codec %d not encodable by kubo; use --output-codec=dag-json", c.Type())
} Try / catch
// CLI: detect and fall back
if out, err := sh.Command("ipfs", "dag", "get", cid).Output(); err != nil {
if strings.Contains(string(err.(*exec.ExitError).Stderr), "invalid encoding") {
return sh.Command("ipfs", "dag", "get", "--output-codec=dag-json", cid).Output()
}
return err
} Prevention
- Prefer standard codecs (dag-cbor, dag-pb, dag-json, raw)
- Inspect CID codec with `ipfs cid format -f %z` before dag get
- Keep kubo/multicodec tables current
When it happens
Trigger: Running `ipfs dag get <cid>` or `ipfs dag get --output-codec=<codec> <cid>` where the requested codec has no registered multicodec encoder in the process (e.g. an exotic or unregistered codec number, or a codec compiled out).
Common situations: Requesting a CID whose codec is not a standard serialization (e.g. raw dag-pb-less CIDs from other ecosystems); using --output-codec with a typo'd or unsupported value such as a codec only known in newer ipld-prime/codec registrations than the installed kubo version; plugins providing codecs not loaded.
Related errors
- internal error encoding node
- core/commands: unexpected type %T, expected *"core/commands"
- supernode routing was never fully implemented and has been r
- unrecognized routing option: %s
- invalid configuration profile: %s
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/548aa877f32fb54a.
Report an issue: GitHub.