lima-vm/lima · error
cannot add global fields to instance data
Error message
cannot add global fields to instance data: %w
What it means
After the message template parses, Inspect calls AddGlobalFields(inst) to build the template data. If that helper fails, the error is recorded and the instance marked StatusBroken. AddGlobalFields computes derived/global view fields for the template data model.
Solutions
- Verify ~/.lima/<inst>/lima.yaml is well-formed and complete
- Update Lima to the latest release (field-derivation bugs are fixed upstream)
- Recreate the instance if its stored YAML cannot be repaired
- File an issue with the Lima project if the error persists on a valid instance
Defensive patterns
Strategy: try-catch
Try / catch
inst, err := store.Inspect(ctx, instDir)
if inst != nil && inst.Status == limatype.StatusBroken {
for _, e := range inst.Errors {
if strings.Contains(e.Error(), "cannot add global fields") {
// treat as internal/state error: update Lima or recreate instance
}
}
} Prevention
- Keep Lima updated; AddGlobalFields failures often indicate version drift
- Ensure lima.yaml is complete and uncorrupted; validate after manual edits
When it happens
Trigger: AddGlobalFields returns an error while deriving global fields (e.g. computing SSH address or other derived instance fields) during `limactl list --format` / Inspect processing.
Common situations: Instance struct in an inconsistent state (missing fields from a partially loaded/corrupted lima.yaml); internal bug after a Lima version change altered FormatData.
Related errors
- cannot execute template %#q
- message %#q is not a valid template
- another hostagent may already be running with pid
- configuration is nil
- configuration is nil
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/a0a7fc56fe1c50eb.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/store/instance.go:132
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()
}
}
}
limaVersionFile := filepath.Join(instDir, filenames.LimaVersion)
if version, err := os.ReadFile(limaVersionFile); err == nil {
inst.LimaVersion = strings.TrimSpace(string(version))
if _, err = versionutil.Parse(inst.LimaVersion); err != nil {View on GitHub (pinned to dd909d0973)