abiosoft/colima · error
error applying nerdctl script template: %w
Error message
error applying nerdctl script template: %w
What it means
Installing the nerdctl wrapper renders an embedded Go text/template (nerdctlScript) with values {ColimaApp: osutil.Executable(), Profile: config.CurrentProfile().ShortName}. This error fires when the template fails to parse or execute — i.e. it references a field not present on the values struct, or the embedded template asset is corrupted. It is an internal invariant break, not an environment condition.
Source
Thrown at cmd/nerdctl.go:119
RunE: func(cmd *cobra.Command, args []string) error {
exists := false
if _, err := os.Stat(nerdctlCmdArgs.path); err == nil && !nerdctlCmdArgs.force && !nerdctlCmdArgs.isColimaScript {
return fmt.Errorf("%s exists, use --force to replace", nerdctlCmdArgs.path)
} else if err == nil {
exists = true
}
var values = struct {
ColimaApp string
Profile string
}{
ColimaApp: osutil.Executable(),
Profile: config.CurrentProfile().ShortName,
}
buf, err := util.ParseTemplate(nerdctlScript, values)
if err != nil {
return fmt.Errorf("error applying nerdctl script template: %w", err)
}
// /usr/local/bin writeable i.e. sudo not needed
// or user-specified install path, we assume user specified path is writeable
if nerdctlCmdArgs.usrBinWriteable || nerdctlCmdArgs.path != nerdctlDefaultInstallPath {
if exists {
if err := os.Rename(nerdctlCmdArgs.path, nerdctlCmdArgs.path+".moved"); err != nil {
return fmt.Errorf("error backing up existing file: %w", err)
}
}
if err := fsutil.MkdirAll("/usr/local/bin", 0755); err != nil {
return nil
}
return os.WriteFile(nerdctlCmdArgs.path, buf, 0755)
}
// sudo is needed for the default path
log.Println("/usr/local/bin not writable, sudo password required to install nerdctl binary")View on GitHub (pinned to c3a5f9184d)
Solutions
- If you patched the template: ensure every {{.Field}} exists on the values struct (ColimaApp, Profile) and the syntax is valid text/template
- Rebuild from a clean checkout: check `git status` for modified embedded assets, then rebuild/reinstall the release binary
- If using a released binary, report it — released templates should always render; meanwhile write the wrapper script manually
Example fix
// before
template: `#!/bin/sh
exec {{.ColimaApp}} nerdctl --profile {{.ProfileName}} "$@"`
// after
template: `#!/bin/sh
exec {{.ColimaApp}} nerdctl --profile {{.Profile}} "$@"` Defensive patterns
Strategy: try-catch
Validate before calling
// template authors: unit-test that the embedded template renders with the values struct
func TestNerdctlTemplateRenders(t *testing.T) {
_, err := util.ParseTemplate(nerdctlScript, struct{ ColimaApp, Profile string }{"colima", "default"})
if err != nil {
t.Fatal(err)
}
} Type guard
// narrow template failures precisely
var execErr template.ExecError
if errors.As(err, &execErr) {
// a field was missing on the values struct; execErr.Name identifies the failing node
} Try / catch
buf, err := util.ParseTemplate(nerdctlScript, values)
if err != nil {
var execErr template.ExecError
if errors.As(err, &execErr) {
return fmt.Errorf("nerdctl template references unknown field in %q", execErr.Name)
}
return fmt.Errorf("error applying nerdctl script template: %w", err)
} Prevention
- Keep template fields in lockstep with the values struct — add a CI unit test rendering nerdctlScript
- Never hand-modify embedded templates in released binaries; rebuild from source instead
When it happens
Trigger: A modified nerdctlScript template referencing fields other than .ColimaApp/.Profile; a build whose embedded template got corrupted or tampered with; go:embed changes dropping the script file so ParseTemplate reads garbage.
Common situations: Contributors editing the template during development; CI builds from a dirty tree; essentially never seen in released binaries.
Related errors
- error retrieving current runtime: empty value
- error reading ssh config: %w
- error at '%s': %w
- cannot make dir: %w
- pid file not found: %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/e616ab296b94faec.
Report an issue: GitHub.