{"id":"5f1d722130103110","repo":"docker/cli","slug":"public-key-file-already-exists-s","errorCode":null,"errorMessage":"public key file already exists: \"%s\"","messagePattern":"public key file already exists: \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/docker-trust/trust/key_generate.go","lineNumber":59,"sourceCode":"}\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)\n}\n\nfunc validateAndGenerateKey(streams command.Streams, keyName string, workingDir string) error {\n\tfreshPassRetGetter := func() notary.PassRetriever { return trust.GetPassphraseRetriever(streams.In(), streams.Out()) }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cmd/docker-trust/trust/key_generate.go#L41-L77","documentation":"Error \"public key file already exists: \"%s\"\" thrown in docker/cli.","triggerScenarios":"Thrown at cmd/docker-trust/trust/key_generate.go:59 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}