lima-vm/lima · error

message %#q is not a valid template: %w

Error message

message %#q is not a valid template: %w

What it means

Inspect() renders the instance's stored lima.yaml 'message' field through a Go text/template. If template.New("format").Parse fails, the message text is not a valid Go template; the instance is marked StatusBroken.

Source

Thrown at pkg/store/instance.go:127

	inst.Networks = y.Networks

	// 0 out values since not configurable on WSL2
	if inst.VMType == limatype.WSL2 {
		inst.Memory = 0
		inst.CPUs = 0
		inst.Disk = 0
	}

	protected := filepath.Join(instDir, filenames.Protected)
	if _, err := os.Lstat(protected); !errors.Is(err, os.ErrNotExist) {
		inst.Protected = true
	}

	inspectStatus(ctx, instDir, inst, y)

	tmpl, err := template.New("format").Parse(y.Message)
	if err != nil {
		inst.Errors = append(inst.Errors, fmt.Errorf("message %#q is not a valid template: %w", y.Message, err))
		inst.Status = limatype.StatusBroken
	} else {
		data, err := AddGlobalFields(inst)
		if err != nil {
			inst.Errors = append(inst.Errors, fmt.Errorf("cannot add global fields to instance data: %w", err))
			inst.Status = limatype.StatusBroken
		} else {
			data.Param = y.Param
			var message strings.Builder
			err = tmpl.Execute(&message, data)
			if err != nil {
				inst.Errors = append(inst.Errors, fmt.Errorf("cannot execute template %#q: %w", y.Message, err))
				inst.Status = limatype.StatusBroken
			} else {
				inst.Message = message.String()
			}
		}
	}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Fix the message field in ~/.lima/<inst>/lima.yaml to be valid Go template syntax (balanced {{ }})
  2. Validate the template locally with `go run` using text/template Parse, or via limactl template validate
  3. Restore the original message from the template the instance was created from
  4. Recreate the instance if the YAML is heavily corrupted

Example fix

// before (invalid template)
message: "VM is running at {{ .HostIPAddress "
// after
message: "VM is running at {{ .HostIPAddress }}"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := template.New("format").Parse(y.Message); err != nil {
    return fmt.Errorf("lima.yaml message is not a valid template: %w", err)
}

Try / catch

inst, err := store.Inspect(ctx, instDir)
if inst.Status == limatype.StatusBroken {
    for _, e := range inst.Errors {
        if strings.Contains(e.Error(), "not a valid template") {
            // repair the message field in lima.yaml before retrying
        }
    }
}

Prevention

When it happens

Trigger: The y.Message stored on the instance contains invalid Go template syntax: unclosed {{ }}, bad pipeline syntax, or unknown parse-time constructs introduced by editing the instance's lima.yaml directly.

Common situations: User hand-edited ~/.lima/<inst>/lima.yaml and broke the message template; copying a message from docs with smart quotes or mismatched braces; using unsupported template functions at parse time.

Related errors


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