{"record":{"id":"e799b06f21127031","repo":"ipfs/kubo","slug":"missing-option-mhlen","errorCode":null,"errorMessage":"missing option \"mhlen\"","messagePattern":"missing option \"mhlen\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/block.go","lineNumber":206,"sourceCode":"\n\t\tcfg, err := nd.Repo.Config()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tmhtype, _ := req.Options[mhtypeOptionName].(string)\n\t\tif mhtype == \"\" {\n\t\t\tmhtype = cfg.Import.HashFunction.WithDefault(config.DefaultHashFunction)\n\t\t}\n\n\t\tmhtval, ok := mh.Names[mhtype]\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unrecognized multihash function: %s\", mhtype)\n\t\t}\n\n\t\tmhlen, ok := req.Options[mhlenOptionName].(int)\n\t\tif !ok {\n\t\t\treturn errors.New(\"missing option \\\"mhlen\\\"\")\n\t\t}\n\n\t\tcidCodec, _ := req.Options[blockCidCodecOptionName].(string)\n\t\tformat, _ := req.Options[blockFormatOptionName].(string) // deprecated\n\n\t\t// use of legacy 'format' needs to suppress 'cid-codec'\n\t\tif format != \"\" {\n\t\t\tif cidCodec != \"\" && cidCodec != \"raw\" {\n\t\t\t\treturn fmt.Errorf(\"unable to use %q (deprecated) and a custom %q at the same time\", blockFormatOptionName, blockCidCodecOptionName)\n\t\t\t}\n\t\t\tcidCodec = \"\" // makes it no-op\n\t\t}\n\n\t\tpin, _ := req.Options[pinOptionName].(bool)\n\n\t\tit := req.Files.Entries()\n\t\tfor it.Next() {\n\t\t\tfile := files.FileFromEntry(it)","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/block.go#L188-L224","documentation":"The --mhlen option is declared with a default of -1, so if the parsed option value is not an int the command treats the option as missing and fails. In practice this fires when the option type assertion fails, indicating an internal options-parsing inconsistency rather than normal user input.","triggerScenarios":"req.Options[mhlenOptionName] is not an int after cmds option parsing — e.g. invoked through a code path that builds the options map manually with a string or float value for 'mhlen', bypassing normal CLI parsing.","commonSituations":"Programmatic invocation of the command Run function with hand-built options; RPC/API layer regression where option values arrive with unexpected types; forks that changed the option declaration.","solutions":["Invoke the command via the normal CLI or /api/v0/ surface so options are parsed correctly","Omit --mhlen entirely (default -1 means use full hash length)","Fix the calling code to pass an int for the mhlen option"],"exampleFix":"// before\nopts[\"mhlen\"] = \"32\" // string breaks assertion\n// after\nopts[\"mhlen\"] = 32   // int","handlingStrategy":"validation","validationCode":"// omit --mhlen or pass it as a plain integer\nipfs block put --mhlen 32 data.bin","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not hand-build the options map when invoking command Run functions programmatically","Leave --mhlen unset unless you specifically need truncated hashes","After upgrading, confirm the option declaration still uses default -1"],"tags":["cli","block-put","options","internal"],"backgroundTag":"missing-option-value","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"}