{"record":{"id":"78ea48d8551e9645","repo":"ipfs/kubo","slug":"paths-must-not-be-empty","errorCode":null,"errorMessage":"paths must not be empty","messagePattern":"paths must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1582,"sourceCode":"\t\tfsn, err := pdir.Child(fname)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tfi, ok := fsn.(*mfs.File)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"expected *mfs.File, didn't get it. This is likely a race condition\")\n\t\t}\n\t\treturn fi, nil\n\n\tdefault:\n\t\treturn nil, err\n\t}\n}\n\nfunc checkPath(p string) (string, error) {\n\tif len(p) == 0 {\n\t\treturn \"\", fmt.Errorf(\"paths must not be empty\")\n\t}\n\n\tif p[0] != '/' {\n\t\treturn \"\", fmt.Errorf(\"paths must start with a leading slash\")\n\t}\n\n\tcleaned := gopath.Clean(p)\n\tif p[len(p)-1] == '/' && p != \"/\" {\n\t\tcleaned += \"/\"\n\t}\n\treturn cleaned, nil\n}\n\nfunc getParentDir(root *mfs.Root, dir string) (*mfs.Directory, error) {\n\tparent, err := mfs.Lookup(root, dir)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":1564,"sourceCodeEnd":1600,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1564-L1600","documentation":"checkPath in core/commands/files.go rejects any MFS path argument with length zero. The files commands operate on absolute paths within the mutable filesystem root, so an empty string can never name a node and is rejected before any lookup happens.","triggerScenarios":"Calling a files command (`files ls`, `files stat`, `files read`, `files rm`, ...) with an empty string as the path argument, e.g. an unset shell variable (`ipfs files stat \"$FILE\"` with FILE empty) or a script bug that drops the argument.","commonSituations":"Shell variables not quoted/initialized in automation; an API caller forwarding an empty `arg` to the /api/v0/files endpoint; a loop variable that came up empty.","solutions":["Ensure the path argument is non-empty before invoking the command (validate or default to \"/\").","Quote shell variables and check `[[ -n \"$FILE\" ]]` before calling `ipfs files`.","In API clients, validate arguments client-side before POSTing to /api/v0/files/*."],"exampleFix":"// before\nFILE=\"\"\nipfs files stat \"$FILE\"   # paths must not be empty\n// after\nFILE=\"${FILE:-/}\"\n[[ -n \"$FILE\" ]] || { echo \"path required\"; exit 1; }\nipfs files stat \"$FILE\"","handlingStrategy":"validation","validationCode":"[ -n \"$P\" ] || { echo \"path required\" >&2; exit 2; }","typeGuard":"func validPath(p string) bool { return len(p) > 0 }","tryCatchPattern":"cleaned, err := checkPath(p)\nif err != nil {\n    if strings.Contains(err.Error(), \"must not be empty\") { return fmt.Errorf(\"-p/--path is required\") }\n    return err\n}","preventionTips":["Quote and default shell vars: \"${FILE:-/}\"","Validate CLI args before invoking `ipfs files *`","In API clients, reject empty `arg` fields client-side"],"tags":["validation","mfs","path","cli"],"backgroundTag":"empty-path-argument","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"}