abiosoft/colima · error
error in template: %w
Error message
error in template: %w
What it means
Returned by `colima template` when configmanager.LoadFrom(tmpFile) fails to parse the edited temp file — the round-trip that validates the user's YAML before it is saved as the template. LoadFrom errors on read failure or yaml.Unmarshal failure, so this means the edited content is invalid YAML or has values that do not fit the config schema (wrong types, bad structure).
Source
Thrown at cmd/template.go:58
if err != nil {
return fmt.Errorf("error reading template file: %w", err)
}
tmpFile, err := waitForUserEdit(templateCmdArgs.Editor, []byte(abort+"\n"+info+"\n"+template))
if err != nil {
return fmt.Errorf("error editing template file: %w", err)
}
if tmpFile == "" {
return fmt.Errorf("empty file, template edit aborted")
}
defer func() {
_ = os.Remove(tmpFile)
}()
// load and resave template to ensure the format is correct
cf, err := configmanager.LoadFrom(tmpFile)
if err != nil {
return fmt.Errorf("error in template: %w", err)
}
if err := configmanager.SaveToFile(cf, templateFile()); err != nil {
return fmt.Errorf("error saving template: %w", err)
}
log.Println("configurations template saved")
return nil
},
}
func templateFile() string { return filepath.Join(config.TemplatesDir(), "default.yaml") }
func templateFileOrDefault() (string, error) {
tFile := templateFile()
if _, err := os.Stat(tFile); err == nil {
b, err := os.ReadFile(tFile)
if err == nil {View on GitHub (pinned to c3a5f9184d)
Solutions
- Re-run `colima template` and fix the reported line/column from the wrapped yaml error
- Replace tabs with spaces and keep 2-space indentation matching the default config
- Start from the pristine default: delete the on-disk template (`rm "$(colima template --print | tail -1)"`) so the embedded default is prefilled, then edit minimally
- Validate before saving: paste the buffer into `yamllint` or `kubectl create --dry-run`-style YAML checkers
Example fix
# before: buffer saved with a tab before 'cpus' Error: error in template: could not load config from file: yaml: line 4: found character that cannot start any token # after: spaces only cpus: 4 memory: 8
Defensive patterns
Strategy: validation
Validate before calling
// Dry-run parse the intended template before putting it in front of a user
func validTemplate(y string) error {
var c config.Config
if err := yaml.Unmarshal([]byte(y), &c); err != nil {
return fmt.Errorf("template YAML invalid: %w", err)
}
return nil
} Try / catch
if err := templateCmd.Execute(); err != nil {
var yte *yaml.TypeError
if errors.As(err, &yte) { // navigate wrapped chain via errors.Unwrap as needed
// show yte.Errors (line/col) to pinpoint the bad lines
}
} Prevention
- Use spaces (2-indent), never tabs, in colima YAML
- Keep the commented abort/info headers intact and edit only real keys
- Lint edited YAML with yamllint before saving from the editor
When it happens
Trigger: Saving the template buffer with tab indentation, broken nesting, or scalar types that do not unmarshal into config.Config fields; editor inserting template placeholders like ${var}; truncation mid-write.
Common situations: YAML beginners using tabs instead of spaces; copy-pasting fragments with inconsistent indentation; VS Code auto-format mangling comment-headered YAML.
Related errors
- error in config file: %w
- uneven children of %d found for mapping node
- error running %s provision script(s)
- colima profile '%s' does not exist
- colima profile '%s' already exists, delete with `colima dele
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/13c3c5f45c6a8f97.
Report an issue: GitHub.