{"record":{"id":"8c2265b5cd2092f8","repo":"ipfs/kubo","slug":"unrecognized-hash-function-q","errorCode":null,"errorMessage":"unrecognized hash function: %q","messagePattern":"unrecognized hash function: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/add.go","lineNumber":453,"sourceCode":"\t\t\t}\n\t\t\t// No explicit preference from user, disable raw-leaves and continue\n\t\t\trbset = true\n\t\t\trawblks = false\n\t\t}\n\n\t\tif onlyHash && toFilesSet {\n\t\t\treturn fmt.Errorf(\"%s and %s options are not compatible\", onlyHashOptionName, toFilesOptionName)\n\t\t}\n\t\tif !dopin && pinNameSet {\n\t\t\treturn fmt.Errorf(\"%s option requires %s to be set\", pinNameOptionName, pinOptionName)\n\t\t}\n\t\tif wrap && toFilesSet {\n\t\t\treturn fmt.Errorf(\"%s and %s options are not compatible\", wrapOptionName, toFilesOptionName)\n\t\t}\n\n\t\thashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unrecognized hash function: %q\", strings.ToLower(hashFunStr))\n\t\t}\n\n\t\tenc, err := cmdenv.GetCidEncoder(req)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\ttoadd := req.Files\n\t\tif wrap {\n\t\t\ttoadd = files.NewSliceDirectory([]files.DirEntry{\n\t\t\t\tfiles.FileEntry(\"\", req.Files),\n\t\t\t})\n\t\t}\n\n\t\topts := []options.UnixfsAddOption{\n\t\t\toptions.Unixfs.Hash(hashFunCode),\n\n\t\t\toptions.Unixfs.Inline(inline),","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/add.go#L435-L471","documentation":"The `--hash` option must name a multihash function known to go-multihash (e.g. sha2-256, blake2b-256, sha3-512). The lowercased value is looked up in mh.Names; if absent, kubo rejects the add before any data is read.","triggerScenarios":"`ipfs add --hash=sha256 file` (wrong alias; correct is sha2-256); `--hash=SHA-256` style variants; config Import.HashFunction containing a misspelled or unsupported name; multihash names unknown to the linked go-multihash table.","commonSituations":"Typos or wrong aliases (sha256 vs sha2-256, blake2b without a size suffix); copying hash names from other tools; configs migrated from implementations with different naming.","solutions":["Use an exact multihash name, e.g. --hash=sha2-256","Verify against known names: sha2-256, sha2-512, sha3-256, sha3-512, blake2b-256, blake2s-256, identity","Fix cfg Import.HashFunction in the config if the resolved default itself is invalid"],"exampleFix":"// before\nipfs add --hash=sha256 file.txt\n// after\nipfs add --hash=sha2-256 file.txt","handlingStrategy":"validation","validationCode":"import \"github.com/multiformats/go-multihash\"\nif _, ok := multihash.Names[strings.ToLower(hashFun)]; !ok {\n  return fmt.Errorf(\"unsupported hash function %q\", hashFun)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use canonical multihash names (sha2-256, sha3-512, blake2b-256)","Lowercase and validate the --hash value before passing it","Keep Import.HashFunction in config limited to known-good values"],"tags":["cli","validation","multihash","hash"],"backgroundTag":"unrecognized-hash-function","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"}