{"record":{"id":"5a939d329481cd9c","repo":"docker/cli","slug":"context-name-cannot-be-empty","errorCode":null,"errorMessage":"context name cannot be empty","messagePattern":"context name cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/context/store/store.go","lineNumber":218,"sourceCode":"// GetTLSData reads, and returns the content of the given fileName for an endpoint.\n// It returns an errdefs.ErrNotFound if the file was not found.\nfunc (s *ContextStore) GetTLSData(contextName, endpointName, fileName string) ([]byte, error) {\n\treturn s.tls.getData(contextName, endpointName, fileName)\n}\n\n// GetStorageInfo returns the paths where the Metadata and TLS data are stored\n// for the context.\nfunc (s *ContextStore) GetStorageInfo(contextName string) StorageInfo {\n\treturn StorageInfo{\n\t\tMetadataPath: s.meta.contextDir(contextdirOf(contextName)),\n\t\tTLSPath:      s.tls.contextDir(contextName),\n\t}\n}\n\n// ValidateContextName checks a context name is valid.\nfunc ValidateContextName(name string) error {\n\tif name == \"\" {\n\t\treturn errors.New(\"context name cannot be empty\")\n\t}\n\tif name == \"default\" {\n\t\treturn errors.New(`\"default\" is a reserved context name`)\n\t}\n\tif !isValidName(name) {\n\t\treturn fmt.Errorf(\"context name %q is invalid, names are validated against regexp %q\", name, validNameFormat)\n\t}\n\treturn nil\n}\n\n// validNameFormat is used as part of errors for invalid context-names.\n// We should consider making this less technical (\"must start with \"a-z\",\n// and only consist of alphanumeric characters and separators\").\nconst validNameFormat = `^[a-zA-Z0-9][a-zA-Z0-9_.+-]+$`\n\n// isValidName checks if the context-name is valid (\"^[a-zA-Z0-9][a-zA-Z0-9_.+-]+$\").\n//\n// Names must start with an alphanumeric character (a-zA-Z0-9), followed by","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/context/store/store.go#L200-L236","documentation":"Returned by ValidateContextName when the provided name is the empty string. Context names are identifiers used in directory paths and CLI commands, so an empty name is rejected before any filesystem operation.","triggerScenarios":"Calling 'docker context create' (or ValidateContextName directly) with an empty name argument. A script that builds the name from an unset variable.","commonSituations":"A CI step parameterizes the context name but the variable is empty. Accidentally hitting enter on a prompt without typing a name.","solutions":["Provide a non-empty context name, e.g. 'docker context create my-remote --docker host=ssh://user@host'.","Ensure any variable used for the name is set and non-empty before invoking the command.","Validate the name upstream with a non-empty check."],"exampleFix":"# before\ndocker context create \"\" --docker host=ssh://user@host\n# after\ndocker context create remote-prod --docker host=ssh://user@host","handlingStrategy":"validation","validationCode":"if name := strings.TrimSpace(ctxName); name == \"\" {\n    return errors.New(\"context name must not be empty\")\n}","typeGuard":"func isNonEmptyName(s string) bool { return strings.TrimSpace(s) != \"\" }","tryCatchPattern":null,"preventionTips":["Ensure context-name variables are set before use.","Call store.ValidateContextName before create operations.","Add a non-empty assertion in CLI wrappers."],"tags":["context","validation","naming"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}