{"record":{"id":"cbe6bcbff02c0273","repo":"docker/cli","slug":"public-key-path-does-not-exist-s","errorCode":null,"errorMessage":"public key path does not exist: \"%s\"","messagePattern":"public key path does not exist: \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/docker-trust/trust/key_generate.go","lineNumber":55,"sourceCode":"\t}\n\tflags := cmd.Flags()\n\tflags.StringVar(&options.directory, \"dir\", \"\", \"Directory to generate key in, defaults to current directory\")\n\treturn cmd\n}\n\n// key names can use lowercase alphanumeric + _ + - characters\nvar validKeyName = lazyregexp.New(`^[a-z0-9][a-z0-9\\_\\-]*$`).MatchString\n\n// validate that all of the key names are unique and are alphanumeric + _ + -\n// and that we do not already have public key files in the target dir on disk\nfunc validateKeyArgs(keyName string, targetDir string) error {\n\tif !validKeyName(keyName) {\n\t\treturn fmt.Errorf(\"key name \\\"%s\\\" must start with lowercase alphanumeric characters and can include \\\"-\\\" or \\\"_\\\" after the first character\", keyName)\n\t}\n\n\tpubKeyFileName := keyName + \".pub\"\n\tif _, err := os.Stat(targetDir); err != nil {\n\t\treturn fmt.Errorf(\"public key path does not exist: \\\"%s\\\"\", targetDir)\n\t}\n\ttargetPath := filepath.Join(targetDir, pubKeyFileName)\n\tif _, err := os.Stat(targetPath); err == nil {\n\t\treturn fmt.Errorf(\"public key file already exists: \\\"%s\\\"\", targetPath)\n\t}\n\treturn nil\n}\n\nfunc setupPassphraseAndGenerateKeys(streams command.Streams, opts keyGenerateOptions) error {\n\ttargetDir := opts.directory\n\tif targetDir == \"\" {\n\t\tcwd, err := os.Getwd()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\ttargetDir = cwd\n\t}\n\treturn validateAndGenerateKey(streams, opts.name, targetDir)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cmd/docker-trust/trust/key_generate.go#L37-L73","documentation":"In validateKeyArgs (key_generate.go:53-56), os.Stat(targetDir) returned an error, meaning the directory where the public key file would be written does not exist (or is inaccessible). targetDir comes from --dir flag or the current working directory (setupPassphraseAndGenerateKeys, key_generate.go:64-72).","triggerScenarios":"Running 'docker trust key generate NAME --dir /nonexistent/path'; the current working directory was deleted or is on an unmounted filesystem after the shell started; --dir points to a path the user lacks permission to stat; a relative --dir that does not resolve.","commonSituations":"Typo in --dir path; script cd'd into a temp dir that was cleaned up; --dir given a file instead of a directory; permission denied on a parent directory; running in a container with a volume not mounted at the expected path.","solutions":["Create the target directory first: mkdir -p <dir>, then re-run with --dir <dir>.","Omit --dir to write to the current working directory, and ensure the cwd exists and is writable.","Check for typos and that the path is a directory (not a file): ls -ld <dir>.","Verify permissions/ownership of the directory and its parents."],"exampleFix":"# before\ndocker trust key generate mykey --dir /tmp/keys  # /tmp/keys missing\n# after\nmkdir -p /tmp/keys && docker trust key generate mykey --dir /tmp/keys","handlingStrategy":"validation","validationCode":"// Ensure the output directory exists and is writable before generating.\nfunc ensureOutputDir(dir string) error {\n    info, err := os.Stat(dir)\n    if err != nil {\n        return fmt.Errorf(\"public key path does not exist: %q\", dir)\n    }\n    if !info.IsDir() {\n        return fmt.Errorf(\"target path is not a directory: %q\", dir)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := os.Stat(targetDir); err != nil {\n    return fmt.Errorf(\"public key path does not exist: %q\", targetDir)\n}","preventionTips":["mkdir -p the target directory in provisioning scripts before key generation.","Default to cwd when --dir is omitted and ensure cwd is valid.","Validate --dir is a directory, not a file."],"tags":["docker","notary","content-trust","filesystem","validation","path"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}