lima-vm/lima · error

the YAML is invalid, saved the buffer as %#q: %w

Error message

the YAML is invalid, saved the buffer as %#q: %w

What it means

limactl instance creation rejected the user's lima.yml because limayaml.Validate() failed during pkg/instance.Create. When the caller opts into saveBrokenYAML, Lima writes the raw input buffer to lima.REJECTED.yaml in the current directory so the user can inspect and fix it, then wraps the validation error with the file name. It is a config-validation guard, not a runtime failure.

Source

Thrown at pkg/instance/create.go:65

	// limayaml.Load() needs to pass the store file path to limayaml.FillDefault() to calculate default MAC addresses
	filePath := filepath.Join(instDir, filenames.LimaYAML)
	loadedInstConfig, err := limayaml.LoadWithWarnings(ctx, instConfig, filePath)
	if err != nil {
		return nil, err
	}
	// If VMType is not specified, we go with the default platform driver.
	if err := driverutil.ResolveVMType(loadedInstConfig); err != nil {
		return nil, err
	}
	if err := limayaml.Validate(loadedInstConfig, false); err != nil {
		if !saveBrokenYAML {
			return nil, err
		}
		rejectedYAML := "lima.REJECTED.yaml"
		if writeErr := os.WriteFile(rejectedYAML, instConfig, 0o644); writeErr != nil {
			return nil, fmt.Errorf("the YAML is invalid, attempted to save the buffer as %#q but failed: %w: %w", rejectedYAML, writeErr, err)
		}
		return nil, fmt.Errorf("the YAML is invalid, saved the buffer as %#q: %w", rejectedYAML, err)
	}
	if err := os.MkdirAll(instDir, 0o700); err != nil {
		return nil, err
	}
	var createSucceeded bool
	defer func() {
		server.Stop(instDir, true)
		if !createSucceeded {
			_ = os.RemoveAll(instDir)
		}
	}()

	if err := os.WriteFile(filePath, instConfig, 0o644); err != nil {
		return nil, err
	}
	if err := os.WriteFile(filepath.Join(instDir, filenames.LimaVersion), []byte(version.Version), 0o444); err != nil {
		return nil, err
	}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Open lima.REJECTED.yaml in the current working directory; the wrapped %w error names each offending field.
  2. Fix the listed fields in your lima.yml (run `limactl validate <file>` if available, or compare against templates/ examples).
  3. If the value depends on host capability, check `limactl info` output for supported arch/vmType.
  4. Pass saveBrokenYAML=false if you want the bare validation error without the saved file.

Example fix

// before
cpus: "not-a-number"
// after
cpus: 4
Defensive patterns

Strategy: validation

Validate before calling

if err := limayaml.Validate(cfg, false); err != nil {
    return fmt.Errorf("invalid lima.yml: %w", err)
}
// or CLI: limactl validate my.yaml before create

Try / catch

if _, err := instance.Create(ctx, name, buf, true); err != nil {
    if strings.Contains(err.Error(), "lima.REJECTED.yaml") {
        // inspect the saved file for the offending config
    }
    return err
}

Prevention

When it happens

Trigger: Calling instance.Create(ctx, instName, instConfig, true) where the YAML parses and loads (limayaml.LoadWithWarnings succeeds at create.go:49) but fails the first strict=false limayaml.Validate at create.go:57, AND os.WriteFile("lima.REJECTED.yaml", ...) succeeds.

Common situations: Hand-written lima.yml with invalid field values (bad arch, unknown vmType, invalid port/forward rules, images without valid URL/arch), deprecated or conflicting fields, or a template filled in with wrong placeholder values.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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