lima-vm/lima · error
failed to marshal template %#q again after filling defaults:
Error message
failed to marshal template %#q again after filling defaults: %w
What it means
After successful validation with `--fill`, the command re-marshals the fully-defaulted YAML with `limayaml.Marshal` to print it. This error wraps a failure of that marshal step — not a validation problem, but an inability to serialize the in-memory LimaYAML back to bytes.
Source
Thrown at cmd/limactl/template.go:281
// Load() will merge the template with override.yaml and default.yaml via FillDefaults().
// FillDefaults() needs the potential instance directory to validate host templates using {{.Dir}}.
filePath := filepath.Join(limaDir, tmpl.Name+".yaml")
y, err := limayaml.Load(ctx, tmpl.Bytes, filePath)
if err != nil {
return err
}
// If VMType is not specified, we go with the default platform driver.
if err := driverutil.ResolveVMType(y); err != nil {
return err
}
if err := limayaml.Validate(y, false); err != nil {
return fmt.Errorf("failed to validate YAML file %#q: %w", arg, err)
}
logrus.Infof("%#q: OK", arg)
if fill {
b, err := limayaml.Marshal(y, len(args) > 1)
if err != nil {
return fmt.Errorf("failed to marshal template %#q again after filling defaults: %w", arg, err)
}
fmt.Fprint(cmd.OutOrStdout(), string(b))
}
}
return nil
}
func newTemplateURLCommand() *cobra.Command {
templateURLCommand := &cobra.Command{
Use: "url CUSTOM_URL",
Short: "Transform custom template URLs to regular file or https URLs",
Args: WrapArgsError(cobra.ExactArgs(1)),
RunE: templateURLAction,
}
return templateURLCommand
}
View on GitHub (pinned to dd909d0973)
Solutions
- Re-run with a single template argument to rule out multi-doc/indent path issues
- Inspect the template for exotic values (very large numbers, unusual nested structures) and simplify them
- Update Lima — if reproducible with stock templates, this indicates a bug; file an issue with the template
- Skip `--fill` and just validate, if you do not need the defaulted output
Example fix
// before limactl template validate --fill a.yaml b.yaml // after limactl template validate --fill a.yaml # isolate which input fails marshaling
Defensive patterns
Strategy: try-catch
Try / catch
b, err := limayaml.Marshal(y, multi)
if err != nil {
return fmt.Errorf("failed to marshal template %q again after filling defaults: %w", arg, err)
} Prevention
- Isolate failures by running --fill on one file at a time
- Avoid exotic values/types in templates that may not round-trip through YAML
- If reproducible with stock templates, report a Lima bug
When it happens
Trigger: Running `limactl template validate --fill <args>` where `limayaml.Marshal(y, len(args) > 1)` returns an error (serialization of the merged/defaulted document failed).
Common situations: Rare; typically only when a custom/monkey-patched type or unusual content in the merged YAML cannot be marshaled by the YAML encoder, or internal bugs in field types.
Related errors
- the YAML is invalid, attempted to save the buffer as %#q but
- the YAML is invalid, saved the buffer as %#q: %w
- invalid parameter %#q, expected NAME=VALUE
- template does not define param %#q
- --verbatim cannot be used with any of --embed, --embed-all,
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/d5ee0b410df5e3a0.
Report an issue: GitHub.