lima-vm/lima · error

identifier %#q must match %v

Error message

identifier %#q must match %v

What it means

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.

Source

Thrown at pkg/identifiers/validate.go:67

// Validate returns nil if the string s is a valid identifier.
//
// Identifiers are similar to the domain name rules according to RFC 1035, section 2.3.1. However
// rules in this package are relaxed to allow numerals to follow period (".") and mixed case is
// allowed.
//
// In general identifiers that pass this validation should be safe for use as filesystem path components.
func Validate(s string) error {
	if s == "" {
		return errors.New("identifier must not be empty")
	}

	if len(s) > maxLength {
		return fmt.Errorf("identifier %#q greater than maximum length (%d characters)", s, maxLength)
	}

	if !identifierRe.MatchString(s) {
		return fmt.Errorf("identifier %#q must match %v", s, identifierRe)
	}
	return nil
}

func reGroup(s string) string {
	return `(?:` + s + `)`
}

func reAnchor(s string) string {
	return `^` + s + `$`
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Rename to match the printed pattern (typically lowercase alphanumerics plus `-` and `_`), e.g. `my-vm` instead of `my vm`
  2. Sanitize generated names: replace disallowed characters with `-` before calling Validate
  3. Use the full name inside instance metadata or the hostname field instead of encoding it in the identifier

Example fix

// before
name := "feature/fix-bug" // '/' not allowed
// after
name := strings.ReplaceAll("feature/fix-bug", "/", "-") // "feature-fix-bug"
Defensive patterns

Strategy: validation

Validate before calling

var identRe = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`) // mirror of the documented pattern; check before calling
if !identRe.MatchString(name) { name = sanitize(name) }

Type guard

func looksLikeIdentifier(s string) bool { return regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`).MatchString(s) }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/91ea793c600c89d2. Report an issue: GitHub.