{"record":{"id":"7aa9a99dd2445e33","repo":"ipfs/kubo","slug":"unknowm-mhtype-d-7aa9a9","errorCode":null,"errorMessage":"unknowm mhType %d","messagePattern":"unknowm mhType (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/rpc/unixfs.go","lineNumber":39,"sourceCode":"\ntype addEvent struct {\n\tName  string\n\tHash  string `json:\",omitempty\"`\n\tBytes int64  `json:\",omitempty\"`\n\tSize  string `json:\",omitempty\"`\n}\n\ntype UnixfsAPI HttpApi\n\nfunc (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.ImmutablePath, error) {\n\toptions, _, err := caopts.UnixfsAddOptions(opts...)\n\tif err != nil {\n\t\treturn path.ImmutablePath{}, err\n\t}\n\n\tmht, ok := mh.Codes[options.MhType]\n\tif !ok {\n\t\treturn path.ImmutablePath{}, fmt.Errorf(\"unknowm mhType %d\", options.MhType)\n\t}\n\n\treq := api.core().Request(\"add\").\n\t\tOption(\"hash\", mht).\n\t\tOption(\"chunker\", options.Chunker).\n\t\tOption(\"cid-version\", options.CidVersion).\n\t\tOption(\"fscache\", options.FsCache).\n\t\tOption(\"inline\", options.Inline).\n\t\tOption(\"inline-limit\", options.InlineLimit).\n\t\tOption(\"nocopy\", options.NoCopy).\n\t\tOption(\"only-hash\", options.OnlyHash).\n\t\tOption(\"pin\", options.Pin).\n\t\tOption(\"silent\", options.Silent).\n\t\tOption(\"progress\", options.Progress)\n\n\tif options.RawLeavesSet {\n\t\treq.Option(\"raw-leaves\", options.RawLeaves)\n\t}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/client/rpc/unixfs.go#L21-L57","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\np, err := c.Unixfs().Add(ctx, f, opts.AddOpts{MhType: 0x1234})\n// after\nimport mh \"github.com/multiformats/go-multihash\"\np, err := c.Unixfs().Add(ctx, f, opts.AddOpts{MhType: mh.SHA2_256})","handlingStrategy":"validation","validationCode":"if _, ok := mh.Codes[opts.MhType]; !ok {\n    return fmt.Errorf(\"unsupported MhType %d; use e.g. mh.SHA2_256\", opts.MhType)\n}","typeGuard":null,"tryCatchPattern":"p, err := c.Unixfs().Add(ctx, f, o)\nif err != nil {\n    if strings.Contains(err.Error(), \"mhType\") {\n        // fall back to default hash\n    }\n    return err\n}","preventionTips":["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"],"tags":["rpc-client","multihash","validation"],"backgroundTag":"unknown-multihash-code","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}