{"record":{"id":"f4c4a5fef9bb8074","repo":"ipfs/kubo","slug":"unexpected-objects-len","errorCode":null,"errorMessage":"unexpected Objects len","messagePattern":"unexpected Objects len","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/rpc/unixfs.go","lineNumber":180,"sourceCode":"\t}\n\tif resp.Error != nil {\n\t\treturn err\n\t}\n\tdefer resp.Close()\n\n\tdec := json.NewDecoder(resp.Output)\n\n\tfor {\n\t\tvar link lsOutput\n\t\tif err = dec.Decode(&link); err != nil {\n\t\t\tif err != io.EOF {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\n\t\tif len(link.Objects) != 1 {\n\t\t\treturn errors.New(\"unexpected Objects len\")\n\t\t}\n\n\t\tif len(link.Objects[0].Links) != 1 {\n\t\t\treturn errors.New(\"unexpected Links len\")\n\t\t}\n\n\t\tl0 := link.Objects[0].Links[0]\n\n\t\tc, err := cid.Decode(l0.Hash)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tvar ftype iface.FileType\n\t\tswitch l0.Type {\n\t\tcase unixfs.TRaw, unixfs.TFile:\n\t\t\tftype = iface.TFile\n\t\tcase unixfs.THAMTShard, unixfs.TDirectory, unixfs.TMetadata:","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/client/rpc/unixfs.go#L162-L198","documentation":"In the RPC client's Ls, each link coming back from the `ls` RPC is expected to carry exactly one Object wrapper (the dag-pb node holding the link). If len(link.Objects) != 1 the response shape doesn't match the dag-pb layout the client assumes, so it errors instead of decoding garbage.","triggerScenarios":"Calling Unixfs().Ls on a path that resolves to a non-dag-pb UnixFS directory node (e.g. a raw or cbor node, or a CIDv1 raw block), so the RPC returns a link with zero or multiple Objects entries.","commonSituations":"Listing a directory added with raw-leaves/CIDv1 where entries are raw blocks; pointing Ls at a single file path instead of a directory; a daemon returning a different response layout than expected.","solutions":["Point Ls at a dag-pb UnixFS directory path, not a raw/ipld node or a single file","Use the dag API (Dag().Get) or IPNS/path resolution to inspect non-dag-pb nodes instead of Unixfs().Ls","Re-add content with standard dag-pb settings (default `ipfs add` recipe) if you need unixfs listing semantics","Upgrade the client/daemon pair so both agree on the `ls` response shape"],"exampleFix":"// before\nl, err := c.Unixfs().Ls(ctx, path.New(\"/ipfs/<raw-cid>\"))\n// after: list a dag-pb directory\nl, err := c.Unixfs().Ls(ctx, path.New(\"/ipfs/<dag-pb-dir-cid>\"))","handlingStrategy":"type-guard","validationCode":"// ensure target is a dag-pb unixfs directory before listing\nnd, err := c.Dag().Get(ctx, p)\nif err == nil && nd.Kind() != ipld.Kind_Map {\n    return errors.New(\"path is not a unixfs directory\")\n}","typeGuard":null,"tryCatchPattern":"entries, err := c.Unixfs().Ls(ctx, p)\nif err != nil {\n    if strings.Contains(err.Error(), \"Objects len\") {\n        // fall back to Dag().Get traversal for non-dag-pb nodes\n    }\n    return err\n}","preventionTips":["Only call Unixfs().Ls on dag-pb UnixFS directories","Use the dag API for raw/cbor nodes","Keep client and daemon versions aligned"],"tags":["rpc-client","unixfs","dag-pb"],"backgroundTag":"unexpected-response-shape","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"}