{"record":{"id":"ffddbd642da21097","repo":"lima-vm/lima","slug":"failed-to-validate-yaml-file-q-w","errorCode":null,"errorMessage":"failed to validate YAML file %#q: %w","messagePattern":"failed to validate YAML file %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/template.go","lineNumber":275,"sourceCode":"\t\t\treturn fmt.Errorf(\"can't determine instance name from template locator %#q\", arg)\n\t\t}\n\t\t// Embed default base.yaml only when fill is true.\n\t\tif err := tmpl.Embed(cmd.Context(), true, fill); err != nil {\n\t\t\treturn err\n\t\t}\n\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\",","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/template.go#L257-L293","documentation":"`limactl template validate` loads the YAML, fills defaults, resolves the VM type, and then runs `limayaml.Validate`. This wrapper error reports that the (default-filled) YAML failed Lima's schema/semantic validation, with the underlying validator error attached via %w.","triggerScenarios":"Running `limactl template validate <file>` (or `--fill`) on a YAML whose content violates limayaml constraints: unknown fields, invalid arch/os/vmType values, bad image URLs, invalid disk/memory sizes, conflicting settings, etc.","commonSituations":"Hand-edited templates with typos (e.g. `cpu: 4` instead of `cpus: 4`); templates copied from older Lima versions using removed/renamed fields; invalid arch like `arm` on an amd64 host; malformed mounts or port mappings.","solutions":["Read the wrapped `%w` cause — it names the offending field and expected values","Fix the reported field in the YAML (correct field names per current Lima schema)","Run `limactl template validate --fill <file>` to see the fully defaulted YAML and confirm resulting values","Test against a known-good template: copy template://default and edit incrementally","Upgrade/downgrade checks: fields from an older Lima version may no longer validate"],"exampleFix":"// before\ncpus: 4        # unknown field\nvm_type: qemu  # wrong name\n// after\ncpus: 4\nvmType: qemu","handlingStrategy":"try-catch","validationCode":"// Sanity-check before invoking validate\nb, err := os.ReadFile(arg)\nif err != nil { return err }\nvar doc map[string]any\nif err := yaml.Unmarshal(b, &doc); err != nil {\n\treturn fmt.Errorf(\"%s is not valid YAML: %w\", arg, err)\n}","typeGuard":null,"tryCatchPattern":"if err := limayaml.Validate(y, false); err != nil {\n\tvar fieldErr *ValidationError\n\tif errors.As(err, &fieldErr) {\n\t\tlog.Printf(\"fix field %s: %v\", fieldErr.Field, fieldErr)\n\t}\n\treturn fmt.Errorf(\"failed to validate YAML file %q: %w\", arg, err)\n}","preventionTips":["Read the wrapped cause message; it names the exact field and constraint","Build templates by editing a known-good one (template://default) rather than from scratch","Re-run `template validate --fill` after every template edit","Keep templates in sync with the Lima version you deploy"],"tags":["cli","yaml","validation","limayaml"],"backgroundTag":"schema-validation-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}