lima-vm/lima · error

invalid network name %#q

Error message

invalid network name %#q: %w

What it means

Each network name in networks.yaml becomes a key used to build file paths and sudoers directives, so it must pass identifiers.Validate. An invalid name aborts config validation with the offending name quoted.

Solutions

  1. Rename the network key in networks.yaml to a valid identifier (letters, digits, underscore, hyphen where allowed) and update all instance YAML `networks` references to the new name.
  2. Re-run validation to confirm no other entries fail.
  3. Check for invisible characters (tabs, non-breaking spaces) with cat -A networks.yaml.
  4. Regenerate the config from the stock template if multiple entries are broken.

Example fix

# before (networks.yaml)
networks:
  "lima user v2":
    mode: user-v2
# after
networks:
  lima-user-v2:
    mode: user-v2
Defensive patterns

Strategy: validation

Validate before calling

function validateNetworkName(name) {
  if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(name)) {
    return `invalid network name: ${JSON.stringify(name)}`;
  }
  return null;
}
Object.keys(config.networks).forEach(validateNetworkName);

Type guard

function isValidNetworkName(name) {
  return typeof name === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(name);
}

Prevention

When it happens

Trigger: Defining a network entry in <LIMA_HOME>/_config/networks.yaml whose key (e.g. under `networks:`) contains whitespace, slashes, newlines, or other non-identifier characters, then running validation via networks.Validate().

Common situations: Hand-edited networks.yaml with a typo like 'lima user-v2' or a name with a trailing colon/space; programmatically generated configs injecting bad keys; YAML merging producing unexpected key names.

Related errors


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

Appendix: source

Thrown at pkg/networks/validate.go:36

)

func (c *Config) Validate() error {
	// The group name and the per-network name/mode/interface are interpolated
	// verbatim into the sudoers file (sudoers.go) and into the socket_vmnet
	// command that reconcile.go runs via sudo after splitting it on spaces
	// (commands.go). A value with whitespace injects an extra argument, and a
	// newline in a network name adds an arbitrary directive to the generated
	// sudoers file, so require them to be valid identifiers. Interface is empty
	// for non-bridged networks, and group defaults to "admin" when unset, so
	// only validate those when a value is actually present.
	if c.Group != "" {
		if err := identifiers.Validate(c.Group); err != nil {
			return fmt.Errorf("invalid group %#q: %w", c.Group, err)
		}
	}
	for name, nw := range c.Networks {
		if err := identifiers.Validate(name); err != nil {
			return fmt.Errorf("invalid network name %#q: %w", name, err)
		}
		if nw.Mode != "" {
			if err := identifiers.Validate(nw.Mode); err != nil {
				return fmt.Errorf("invalid mode %#q for network %#q: %w", nw.Mode, name, err)
			}
		}
		if nw.Interface != "" {
			if err := identifiers.Validate(nw.Interface); err != nil {
				return fmt.Errorf("invalid interface %#q for network %#q: %w", nw.Interface, name, err)
			}
		}
	}

	// validate all paths.* values
	paths := reflect.ValueOf(&c.Paths).Elem()
	pathsMap := make(map[string]string, paths.NumField())
	var socketVMNetNotFound bool
	for i := range paths.NumField() {

View on GitHub (pinned to dd909d0973)