{"record":{"id":"3e0477e19850e3eb","repo":"ipfs/kubo","slug":"no-cid-in-path-s","errorCode":null,"errorMessage":"no cid in path: %s","messagePattern":"no cid in path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/commands/cmdenv/cidbase.go","lineNumber":87,"sourceCode":"// `CidLike`, `CidLike/...`, or `/namespace/CidLike/...`.\n//\n// For example:\n//\n// * Qm...\n// * Qm.../...\n// * /ipfs/Qm...\n// * /ipns/bafybeiahnxfi7fpmr5wtxs2imx4abnyn7fdxeiox7xxjem6zuiioqkh6zi/...\n// * /bzz/bafybeiahnxfi7fpmr5wtxs2imx4abnyn7fdxeiox7xxjem6zuiioqkh6zi/...\nfunc CidEncoderFromPath(p string) (cidenc.Encoder, error) {\n\tcomponents := strings.SplitN(p, \"/\", 4)\n\n\tvar maybeCid string\n\tif components[0] != \"\" {\n\t\t// No leading slash, first component is likely CID-like.\n\t\tmaybeCid = components[0]\n\t} else if len(components) < 3 {\n\t\t// Not enough components to include a CID.\n\t\treturn cidenc.Encoder{}, fmt.Errorf(\"no cid in path: %s\", p)\n\t} else {\n\t\tmaybeCid = components[2]\n\t}\n\tc, err := cid.Decode(maybeCid)\n\tif err != nil {\n\t\t// Ok, not a CID-like thing. Keep the current encoder.\n\t\treturn cidenc.Encoder{}, fmt.Errorf(\"no cid in path: %s\", p)\n\t}\n\tif c.Version() == 0 {\n\t\t// Version 0, use the base58 non-upgrading encoder.\n\t\treturn cidenc.Default(), nil\n\t}\n\n\t// Version 1+, extract multibase encoding.\n\tencoding, _, err := mbase.Decode(maybeCid)\n\tif err != nil {\n\t\t// This should be impossible, we've already decoded the cid.\n\t\tpanic(fmt.Sprintf(\"BUG: failed to get multibase decoder for CID %s\", maybeCid))","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/cmdenv/cidbase.go#L69-L105","documentation":"CidEncoderFromPath extracts a CID from a path string to pick a matching output multibase encoder. If the path has no leading slash and fewer than 3 components (so no component can hold a CID), it gives up with 'no cid in path'.","triggerScenarios":"Calling cmdenv.CidEncoderFromPath(p) with a path like \"foo/bar\" (no leading '/', fewer than 3 components) or any string too short to contain a CID component.","commonSituations":"Passing bare keys, relative two-segment paths, or non-path identifiers from commands that only sometimes carry CIDs; tests constructing minimal path strings.","solutions":["Pass a full path containing a valid CID, e.g. /ipfs/<cid>/... or a 3-component path whose third element is the CID","Treat the returned error as 'no encoder change needed' if your caller only uses this opportunistically (the function's contract allows callers to ignore it)","Check whether the code path should be supplying a path at all"],"exampleFix":"// before\nenc, _ := cmdenv.CidEncoderFromPath(\"foo/bar\")\n// after\nenc, err := cmdenv.CidEncoderFromPath(\"/ipfs/bafybe.../\")","handlingStrategy":"fallback","validationCode":"parts := strings.Split(path, \"/\")\nhasCid := len(parts) >= 3 || (len(parts) > 0 && parts[0] != \"\")","typeGuard":null,"tryCatchPattern":"enc, err := cmdenv.CidEncoderFromPath(p)\nif err != nil {\n    enc = cidenc.Default() // keep default encoder, non-fatal\n}","preventionTips":["Only pass paths that contain a CID component","Treat CidEncoderFromPath errors as advisory, not fatal","Log-and-continue is the intended pattern for this helper"],"tags":["cid","path-parsing","encoder"],"backgroundTag":"no-cid-in-path","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"}