{"record":{"id":"44c14aa280071a5f","repo":"ipfs/kubo","slug":"w-v","errorCode":null,"errorMessage":"%w: %v","messagePattern":"%w: %v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":562,"sourceCode":"\t\tnode, err := getNodeFromPath(req.Context, nd, api, src)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cp: cannot get node from path %s: %s\", src, err)\n\t\t}\n\n\t\t// Sanity-check: ensure root CID is a valid UnixFS (dag-pb or raw block)\n\t\t// Context: https://github.com/ipfs/kubo/issues/10331\n\t\tsrcCidType := node.Cid().Type()\n\t\tswitch srcCidType {\n\t\tcase cid.Raw:\n\t\t\tif _, ok := node.(*dag.RawNode); !ok {\n\t\t\t\treturn errFilesCpInvalidUnixFS\n\t\t\t}\n\t\tcase cid.DagProtobuf:\n\t\t\tif _, ok := node.(*dag.ProtoNode); !ok {\n\t\t\t\treturn errFilesCpInvalidUnixFS\n\t\t\t}\n\t\t\tif _, err = ft.FSNodeFromBytes(node.(*dag.ProtoNode).Data()); err != nil {\n\t\t\t\treturn fmt.Errorf(\"%w: %v\", errFilesCpInvalidUnixFS, err)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn errFilesCpInvalidUnixFS\n\t\t}\n\n\t\tmkParents, _ := req.Options[filesParentsOptionName].(bool)\n\t\tif mkParents {\n\t\t\tmaxDirLinks := int(cfg.Import.UnixFSDirectoryMaxLinks.WithDefault(config.DefaultUnixFSDirectoryMaxLinks))\n\t\t\tsizeEstimationMode := cfg.Import.HAMTSizeEstimationMode()\n\t\t\terr := ensureContainingDirectoryExists(nd.FilesRoot, dst,\n\t\t\t\tmfs.WithCidBuilder(prefix),\n\t\t\t\tmfs.WithMaxLinks(maxDirLinks),\n\t\t\t\tmfs.WithSizeEstimationMode(sizeEstimationMode),\n\t\t\t)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L544-L580","documentation":"The source CID is dag-pb but the dag-pb block's embedded UnixFS data failed to parse (ft.FSNodeFromBytes error), so it is not a valid UnixFS node. The error message renders as \"cp: source must be a valid UnixFS (dag-pb or raw codec): <parse error>\" — the %w wraps errFilesCpInvalidUnixFS so errors.Is against it still matches.","triggerScenarios":"Running `ipfs files cp /ipfs/<cid> /dst` where <cid> is dag-pb but its protobuf data is not a valid UnixFS FSNode — e.g. a bare dag-pb IPLD document that was created with `ipfs dag put` (no unixfs encoding) rather than `ipfs add`.","commonSituations":"Putting arbitrary protobuf data with `ipfs dag put --store-codec dag-pb` and then trying to cp it into MFS; corrupted dag-pb blocks; hand-crafted dag-pb documents without UnixFS Data field.","solutions":["Confirm the block is real UnixFS: `ipfs dag get <cid> | head` or `ipfs ls /ipfs/<cid>` (ls works only on UnixFS)","Re-add the original bytes with `ipfs add` to get a proper UnixFS dag-pb node","If the content is a raw dag-pb IPLD document, it cannot be placed in MFS; export and re-add as a file","Use `ipfs files cp` only with CIDs produced by `ipfs add` or raw blocks"],"exampleFix":"// before: dag-put output copied into MFS\nipfs dag put --store-codec dag-pb data.pb\nipfs files cp /ipfs/<cid> /my-file  // fails\n\n// after\nipfs add -q data\nipfs files cp /ipfs/<new-cid> /my-file","handlingStrategy":"validation","validationCode":"// dag-pb CIDs must come from ipfs add (UnixFS), not dag put\nif isDagPbButFromDagPut(cid) {\n    return fmt.Errorf(\"re-add content with `ipfs add` before files cp\")\n}","typeGuard":"func isValidUnixFSDagPb(cid string) bool {\n    // `ipfs ls` succeeds only on UnixFS dag-pb nodes\n    return run(\"ipfs\", \"ls\", \"/ipfs/\"+cid) == nil\n}","tryCatchPattern":"if err := ipfsFilesCp(src, dst); err != nil {\n    if errors.Is(err, errFilesCpInvalidUnixFS) {\n        // export original bytes and re-add with `ipfs add`\n    }\n}","preventionTips":["Never feed `ipfs dag put` output directly into `ipfs files cp`","Validate with `ipfs ls /ipfs/<cid>` first — it only works on UnixFS","Track CID provenance: prefer `ipfs add`-produced CIDs for MFS ops"],"tags":["mfs","cli","unixfs","dag-pb"],"backgroundTag":"invalid-unixfs-source","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"}