{"record":{"id":"453a3a43fcc4b108","repo":"ipfs/kubo","slug":"this-dag-node-is-a-directory","errorCode":null,"errorMessage":"this dag node is a directory","messagePattern":"this dag node is a directory","errorType":"exception","errorClass":"ErrIsDir","httpStatus":null,"severity":"error","filePath":"core/coreiface/errors.go","lineNumber":6,"sourceCode":"package iface\n\nimport \"errors\"\n\nvar (\n\tErrIsDir        = errors.New(\"this dag node is a directory\")\n\tErrNotFile      = errors.New(\"this dag node is not a regular file\")\n\tErrOffline      = errors.New(\"this action must be run in online mode, try running 'ipfs daemon' first\")\n\tErrNotSupported = errors.New(\"operation not supported\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":11,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreiface/errors.go#L1-L11","documentation":"`iface.ErrIsDir` is a sentinel error in kubo's CoreAPI interface package indicating that the requested DAG node is a UnixFS directory rather than a regular file. Operations like `cat` can only stream file content, so when the resolved node is a directory the API refuses with this sentinel so callers can detect the case programmatically via errors.Is.","triggerScenarios":"Calling `api.Unixfs().Get`/`Cat` (or the `ipfs cat` CLI path) on a path/CID that resolves to a UnixFS directory node; in core/commands/cat.go the `files.Directory` case returns iface.ErrIsDir directly.","commonSituations":"Users running `ipfs cat <dir-cid>` on a directory root (very common — the CID points at a folder, not a file); scripts assuming a CID is a file; CID resolving to a directory after a path component was dropped or mistyped.","solutions":["Use `ipfs ls <path>` (or `api.Unixfs().Ls`) instead of cat when the target is a directory.","Append the file name to the path to address a file inside the directory, e.g. `ipfs cat <dir-cid>/readme.md`.","In code, detect the case with `errors.Is(err, iface.ErrIsDir)` and switch to a directory-listing API."],"exampleFix":"// before\nr, err := api.Unixfs().Get(ctx, p)\n// after\nnode, err := api.Unixfs().Get(ctx, p)\nif errors.Is(err, iface.ErrIsDir) {\n    dir, _ := mfs.NewDirectory(...) // or use api.Unixfs().Ls(ctx, p)\n    return handleDirectory(dir)\n}","handlingStrategy":"type-guard","validationCode":"// Before cat, check the node kind:\nstat, err := api.Unixfs().Ls(ctx, p)\n// if Ls succeeds and entries exist, the path is a directory — use ls, not cat","typeGuard":"func isDirectory(node files.Node) bool {\n    _, ok := node.(files.Directory)\n    return ok\n}","tryCatchPattern":"node, err := api.Unixfs().Get(ctx, p)\nif err != nil {\n    if errors.Is(err, iface.ErrIsDir) {\n        return listDirectory(ctx, p) // switch to ls/Ls\n    }\n    return err\n}","preventionTips":["Use `ipfs ls` to confirm the target is a file before `ipfs cat`","Address files inside directories explicitly: <dir-cid>/filename","Never assume a bare CID is a file; resolve the path fully first"],"tags":["unixfs","coreapi","sentinel-error","ipfs"],"backgroundTag":"node-is-directory","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"}