{"record":{"id":"77c22bdd7034eb6e","repo":"ipfs/kubo","slug":"unknowm-mhtype-d","errorCode":null,"errorMessage":"unknowm mhType %d","messagePattern":"unknowm mhType (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/rpc/block.go","lineNumber":43,"sourceCode":"\nfunc (s *blockStat) Size() int {\n\treturn s.BSize\n}\n\nfunc (s *blockStat) Path() path.ImmutablePath {\n\treturn path.FromCid(s.cid)\n}\n\nfunc (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error) {\n\toptions, err := caopts.BlockPutOptions(opts...)\n\tpx := options.CidPrefix\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tmht, ok := mh.Codes[px.MhType]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unknowm mhType %d\", px.MhType)\n\t}\n\n\tvar cidOptKey, cidOptVal string\n\tswitch {\n\tcase px.Version == 0 && px.Codec == cid.DagProtobuf:\n\t\t// ensure legacy --format=v0 passes as BlockPutOption still works\n\t\tcidOptKey = \"format\"\n\t\tcidOptVal = \"v0\"\n\tdefault:\n\t\t// pass codec as string\n\t\tcidOptKey = \"cid-codec\"\n\t\tcidOptVal = mc.Code(px.Codec).String()\n\t}\n\n\treq := api.core().Request(\"block/put\").\n\t\tOption(\"mhtype\", mht).\n\t\tOption(\"mhlen\", px.MhLength).\n\t\tOption(cidOptKey, cidOptVal).","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/client/rpc/block.go#L25-L61","documentation":"BlockAPI.Put validates the requested multihash type by looking up px.MhType in the mh.Codes table; if the code is not a registered multihash function it returns this error (note the 'unknowm' typo in the message). The client refuses to ask the daemon to build a block with a hash function it cannot name.","triggerScenarios":"Calling api.Block().Put(ctx, reader, opts.Block.MhType(x).Codec(cidCode).Format(format)) where x is 0, a negative value, or an unregistered/proprietary multihash code not present in mh.Codes.","commonSituations":"Hand-written constants for MhType (e.g. 0x00 or a typo'd hex value), custom hash functions registered only on the daemon but not in the client's multihash table, or copying option values from an old example that predates the multihash registry.","solutions":["Use a registered multihash constant, e.g. mh.SHA2_256 (0x12), mh.SHA2_512 (0x40), mh.SHA3_256 (0x16), mh.BLAKE2B_MIN+31, or mh.IDENTITY (0x00 is NOT identity; use mh.IDENTITY for raw identity hashes).","If you need a custom multihash code, register it with mh.Codes before calling Put so the lookup succeeds.","Check the value you pass to opts.Block.MhType against the table in github.com/multiformats/go-multihash (mh.Codes) to confirm it is registered."],"exampleFix":"// before\nblk, err := api.Block().Put(ctx, r, opts.Block.MhType(0x00).Codec(cid.DagProtobuf).Format(\"cbor\"))\n// after\nblk, err := api.Block().Put(ctx, r, opts.Block.MhType(mh.SHA2_256).Codec(cid.DagProtobuf).Format(\"cbor\"))","handlingStrategy":"validation","validationCode":"if _, ok := mh.Codes[mhType]; !ok {\n    return fmt.Errorf(\"mhType %d is not a registered multihash code\", mhType)\n}\n// proceed to api.Block().Put with opts.Block.MhType(mhType)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use named constants (mh.SHA2_256, mh.IDENTITY) instead of numeric literals for MhType","Register any custom multihash code with mh.Codes before calling Put","Consult go-multihash mh.Codes when unsure whether a code is supported"],"tags":["block","multihash","http-rpc","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"}