{"record":{"id":"29cebc9a19e91097","repo":"docker/cli","slug":"invalid-output-path-directory-q-does-not-exist","errorCode":null,"errorMessage":"invalid output path: directory %q does not exist","messagePattern":"invalid output path: directory %q does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/utils.go","lineNumber":66,"sourceCode":"\t\t\t// \"label != some-value\" conflicts with \"label = some-value\"\n\t\t\tif pruneFilters[\"label\"][v] {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tpruneFilters.Add(k, v)\n\t\tdefault:\n\t\t\tpruneFilters.Add(k, v)\n\t\t}\n\t}\n\n\treturn pruneFilters\n}\n\n// ValidateOutputPath validates the output paths of the \"docker cp\" command.\nfunc ValidateOutputPath(path string) error {\n\tdir := filepath.Dir(filepath.Clean(path))\n\tif dir != \"\" && dir != \".\" {\n\t\tif _, err := os.Stat(dir); os.IsNotExist(err) {\n\t\t\treturn fmt.Errorf(\"invalid output path: directory %q does not exist\", dir)\n\t\t}\n\t}\n\t// check whether `path` points to a regular file\n\t// (if the path exists and doesn't point to a directory)\n\tif fileInfo, err := os.Stat(path); !os.IsNotExist(err) {\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif fileInfo.Mode().IsDir() || fileInfo.Mode().IsRegular() {\n\t\t\treturn nil\n\t\t}\n\n\t\tif err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid output path: %q must be a directory or a regular file: %w\", path, err)\n\t\t}\n\t}\n\treturn nil","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/utils.go#L48-L84","documentation":"Returned by ValidateOutputPath when the parent directory of a requested output path does not exist on disk. ValidateOutputPath is the validator used by the `docker cp` command to sanity-check the local destination before copying a file out of a container (cli/command/utils.go:62). It takes filepath.Dir of the cleaned path and runs os.Stat on it; if that reports IsNotExist, the copy is rejected up front rather than failing mid-transfer.","triggerScenarios":"Calling ValidateOutputPath(\"/nonexistent/dir/file.tar\") (or any docker cp whose destination's parent dir is missing). The check at utils.go:64-66 triggers when dir != \".\" and os.Stat(dir) returns an IsNotExist error.","commonSituations":"Typo in a destination path; passing a path under a directory you forgot to create; an output dir that lives inside a mount that isn't mounted yet; CI runners where the working directory layout differs from local.","solutions":["Create the parent directory first: mkdir -p <dir> before running docker cp.","Verify the destination spelling and that you are pointing at a real path with ls <dir>.","If the dir was supposed to exist, check that the volume/mount backing it is attached."],"exampleFix":"// before\ndocker cp mycontainer:/data/out.tar /opt/exports/notcreated/out.tar\n// after (create the parent first)\nmkdir -p /opt/exports/notcreated && docker cp mycontainer:/data/out.tar /opt/exports/notcreated/out.tar","handlingStrategy":"validation","validationCode":"// Verify the parent dir exists before calling ValidateOutputPath.\nfunc ensureOutputPath(path string) error {\n    dir := filepath.Dir(filepath.Clean(path))\n    if dir != \"\" && dir != \".\" {\n        if _, err := os.Stat(dir); os.IsNotExist(err) {\n            if err := os.MkdirAll(dir, 0o755); err != nil {\n                return err\n            }\n        }\n    }\n    return nil\n}\n// usage:\n// if err := ensureOutputPath(dest); err != nil { return err }\n// if err := command.ValidateOutputPath(dest); err != nil { return err }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create destination directories with mkdir -p (or os.MkdirAll) before invoking docker cp or ValidateOutputPath.","Validate output paths early in your command flow so the error surfaces before any transfer starts.","Reject or auto-create missing parent dirs explicitly rather than relying on the default error."],"tags":["docker-cp","output-path","filesystem","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}