ipfs/kubo · error
unknowm mhType %d
Error message
unknowm mhType %d
What it means
The RPC client's Add validates options.MhType against the mh.Codes multihash code table before sending the request. If the supplied code has no entry in that map, it refuses to build the `add` request (which would otherwise set an invalid `hash` option) and returns this error. Note the message contains a typo ('unknowm').
Source
Thrown at client/rpc/unixfs.go:39
type addEvent struct {
Name string
Hash string `json:",omitempty"`
Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"`
}
type UnixfsAPI HttpApi
func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.ImmutablePath, error) {
options, _, err := caopts.UnixfsAddOptions(opts...)
if err != nil {
return path.ImmutablePath{}, err
}
mht, ok := mh.Codes[options.MhType]
if !ok {
return path.ImmutablePath{}, fmt.Errorf("unknowm mhType %d", options.MhType)
}
req := api.core().Request("add").
Option("hash", mht).
Option("chunker", options.Chunker).
Option("cid-version", options.CidVersion).
Option("fscache", options.FsCache).
Option("inline", options.Inline).
Option("inline-limit", options.InlineLimit).
Option("nocopy", options.NoCopy).
Option("only-hash", options.OnlyHash).
Option("pin", options.Pin).
Option("silent", options.Silent).
Option("progress", options.Progress)
if options.RawLeavesSet {
req.Option("raw-leaves", options.RawLeaves)
}View on GitHub (pinned to 329838acdf)
Solutions
- Set MhType to a supported code such as mh.SHA2_256 (0x12) or mh.BLAKE2B_MIN+32, or leave it at the default (mh.SHA2_256) instead of passing an unknown value
- Look up valid codes in the github.com/multiformats/go-multihash package used by the client and pick one of its exported constants
- Upgrade the client library if you need a hash function whose code was added recently
- Check that the daemon also supports the chosen hash if using a non-SHA2-256 hash
Example fix
// before
p, err := c.Unixfs().Add(ctx, f, opts.AddOpts{MhType: 0x1234})
// after
import mh "github.com/multiformats/go-multihash"
p, err := c.Unixfs().Add(ctx, f, opts.AddOpts{MhType: mh.SHA2_256}) Defensive patterns
Strategy: validation
Validate before calling
if _, ok := mh.Codes[opts.MhType]; !ok {
return fmt.Errorf("unsupported MhType %d; use e.g. mh.SHA2_256", opts.MhType)
} Try / catch
p, err := c.Unixfs().Add(ctx, f, o)
if err != nil {
if strings.Contains(err.Error(), "mhType") {
// fall back to default hash
}
return err
} Prevention
- Always set MhType from go-multihash exported constants, never raw numbers
- Omit MhType to get the default SHA2-256
- Validate the code against mh.Codes before constructing AddOpts
When it happens
Trigger: Calling client/rpc Unixfs().Add (or AddAsync) with AddOpts.MhType set to a multihash code that is not a key of mh.Codes — e.g. an arbitrary or zero value, or a code from a newer multihash registry than the client library knows.
Common situations: Hardcoding a multihash constant from memory; passing 0 as MhType intending 'default'; using a custom/new hash function code the bundled multihash table doesn't recognize.
Related errors
- unknowm mhType %d
- Import.HashFunction unrecognized: %q
- unrecognized hash function: %q
- only sha2-255-32 is allowed with CIDv0
- unexpected Objects len
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/7aa9a99dd2445e33.
Report an issue: GitHub.