{"record":{"id":"91ea793c600c89d2","repo":"lima-vm/lima","slug":"identifier-q-must-match-v","errorCode":null,"errorMessage":"identifier %#q must match %v","messagePattern":"identifier %#q must match (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/identifiers/validate.go","lineNumber":67,"sourceCode":"\n// Validate returns nil if the string s is a valid identifier.\n//\n// Identifiers are similar to the domain name rules according to RFC 1035, section 2.3.1. However\n// rules in this package are relaxed to allow numerals to follow period (\".\") and mixed case is\n// allowed.\n//\n// In general identifiers that pass this validation should be safe for use as filesystem path components.\nfunc Validate(s string) error {\n\tif s == \"\" {\n\t\treturn errors.New(\"identifier must not be empty\")\n\t}\n\n\tif len(s) > maxLength {\n\t\treturn fmt.Errorf(\"identifier %#q greater than maximum length (%d characters)\", s, maxLength)\n\t}\n\n\tif !identifierRe.MatchString(s) {\n\t\treturn fmt.Errorf(\"identifier %#q must match %v\", s, identifierRe)\n\t}\n\treturn nil\n}\n\nfunc reGroup(s string) string {\n\treturn `(?:` + s + `)`\n}\n\nfunc reAnchor(s string) string {\n\treturn `^` + s + `$`\n}\n","sourceCodeStart":49,"sourceCodeEnd":79,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/identifiers/validate.go#L49-L79","documentation":"Validate rejects identifiers that do not match identifierRe, the regexp of permitted characters/shape (alphanumerics and limited punctuation, no leading/trailing specials). The error echoes the pattern so users know the required format. Lima restricts the charset because identifiers become directory names and shell arguments.","triggerScenarios":"Any call path into identifiers.Validate (ValidateInstName, InstNameFromYAMLPath, ValidateTemplateArgs, DiskDir) with a string containing disallowed characters, e.g. spaces, slashes, `:` in `limactl create --name=\"my vm\"` or a name with a Windows drive prefix.","commonSituations":"Names copied from URLs or file paths; uppercase/accented characters if the regex is lowercase-only; names generated from branch names containing `/`; template args passing hostnames with underscores or dots.","solutions":["Rename to match the printed pattern (typically lowercase alphanumerics plus `-` and `_`), e.g. `my-vm` instead of `my vm`","Sanitize generated names: replace disallowed characters with `-` before calling Validate","Use the full name inside instance metadata or the hostname field instead of encoding it in the identifier"],"exampleFix":"// before\nname := \"feature/fix-bug\" // '/' not allowed\n// after\nname := strings.ReplaceAll(\"feature/fix-bug\", \"/\", \"-\") // \"feature-fix-bug\"","handlingStrategy":"validation","validationCode":"var identRe = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`) // mirror of the documented pattern; check before calling\nif !identRe.MatchString(name) { name = sanitize(name) }","typeGuard":"func looksLikeIdentifier(s string) bool { return regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`).MatchString(s) }","tryCatchPattern":null,"preventionTips":["Sanitize generated names: lowercase, replace disallowed chars with '-'","Avoid deriving names from URLs, paths, or branch names verbatim","Print the regex from the error message when surfacing failures to users"],"tags":["validation","identifier","regexp"],"backgroundTag":"invalid-identifier-format","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}