{"record":{"id":"d5ee0b410df5e3a0","repo":"lima-vm/lima","slug":"failed-to-marshal-template-q-again-after-filling","errorCode":null,"errorMessage":"failed to marshal template %#q again after filling defaults: %w","messagePattern":"failed to marshal template %#q again after filling defaults: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/template.go","lineNumber":281,"sourceCode":"\t\t// Load() will merge the template with override.yaml and default.yaml via FillDefaults().\n\t\t// FillDefaults() needs the potential instance directory to validate host templates using {{.Dir}}.\n\t\tfilePath := filepath.Join(limaDir, tmpl.Name+\".yaml\")\n\t\ty, err := limayaml.Load(ctx, tmpl.Bytes, filePath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t// If VMType is not specified, we go with the default platform driver.\n\t\tif err := driverutil.ResolveVMType(y); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := limayaml.Validate(y, false); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to validate YAML file %#q: %w\", arg, err)\n\t\t}\n\t\tlogrus.Infof(\"%#q: OK\", arg)\n\t\tif fill {\n\t\t\tb, err := limayaml.Marshal(y, len(args) > 1)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to marshal template %#q again after filling defaults: %w\", arg, err)\n\t\t\t}\n\t\t\tfmt.Fprint(cmd.OutOrStdout(), string(b))\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc newTemplateURLCommand() *cobra.Command {\n\ttemplateURLCommand := &cobra.Command{\n\t\tUse:   \"url CUSTOM_URL\",\n\t\tShort: \"Transform custom template URLs to regular file or https URLs\",\n\t\tArgs:  WrapArgsError(cobra.ExactArgs(1)),\n\t\tRunE:  templateURLAction,\n\t}\n\treturn templateURLCommand\n}\n","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/template.go#L263-L299","documentation":"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.","triggerScenarios":"Running `limactl template validate --fill <args>` where `limayaml.Marshal(y, len(args) > 1)` returns an error (serialization of the merged/defaulted document failed).","commonSituations":"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.","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"],"exampleFix":"// before\nlimactl template validate --fill a.yaml b.yaml\n// after\nlimactl template validate --fill a.yaml   # isolate which input fails marshaling","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"b, err := limayaml.Marshal(y, multi)\nif err != nil {\n\treturn fmt.Errorf(\"failed to marshal template %q again after filling defaults: %w\", arg, err)\n}","preventionTips":["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"],"tags":["cli","template","marshal","yaml"],"backgroundTag":"yaml-marshal-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}