{"record":{"id":"e616ab296b94faec","repo":"abiosoft/colima","slug":"error-applying-nerdctl-script-template-w","errorCode":null,"errorMessage":"error applying nerdctl script template: %w","messagePattern":"error applying nerdctl script template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/nerdctl.go","lineNumber":119,"sourceCode":"\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\texists := false\n\t\t\tif _, err := os.Stat(nerdctlCmdArgs.path); err == nil && !nerdctlCmdArgs.force && !nerdctlCmdArgs.isColimaScript {\n\t\t\t\treturn fmt.Errorf(\"%s exists, use --force to replace\", nerdctlCmdArgs.path)\n\t\t\t} else if err == nil {\n\t\t\t\texists = true\n\t\t\t}\n\n\t\t\tvar values = struct {\n\t\t\t\tColimaApp string\n\t\t\t\tProfile   string\n\t\t\t}{\n\t\t\t\tColimaApp: osutil.Executable(),\n\t\t\t\tProfile:   config.CurrentProfile().ShortName,\n\t\t\t}\n\t\t\tbuf, err := util.ParseTemplate(nerdctlScript, values)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error applying nerdctl script template: %w\", err)\n\t\t\t}\n\n\t\t\t// /usr/local/bin writeable i.e. sudo not needed\n\t\t\t// or user-specified install path, we assume user specified path is writeable\n\t\t\tif nerdctlCmdArgs.usrBinWriteable || nerdctlCmdArgs.path != nerdctlDefaultInstallPath {\n\t\t\t\tif exists {\n\t\t\t\t\tif err := os.Rename(nerdctlCmdArgs.path, nerdctlCmdArgs.path+\".moved\"); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"error backing up existing file: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif err := fsutil.MkdirAll(\"/usr/local/bin\", 0755); err != nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\treturn os.WriteFile(nerdctlCmdArgs.path, buf, 0755)\n\t\t\t}\n\n\t\t\t// sudo is needed for the default path\n\t\t\tlog.Println(\"/usr/local/bin not writable, sudo password required to install nerdctl binary\")","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/nerdctl.go#L101-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"Contributors editing the template during development; CI builds from a dirty tree; essentially never seen in released binaries.","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"],"exampleFix":"// before\ntemplate: `#!/bin/sh\nexec {{.ColimaApp}} nerdctl --profile {{.ProfileName}} \"$@\"`\n\n// after\ntemplate: `#!/bin/sh\nexec {{.ColimaApp}} nerdctl --profile {{.Profile}} \"$@\"`","handlingStrategy":"try-catch","validationCode":"// template authors: unit-test that the embedded template renders with the values struct\nfunc TestNerdctlTemplateRenders(t *testing.T) {\n    _, err := util.ParseTemplate(nerdctlScript, struct{ ColimaApp, Profile string }{\"colima\", \"default\"})\n    if err != nil {\n        t.Fatal(err)\n    }\n}","typeGuard":"// narrow template failures precisely\nvar execErr template.ExecError\nif errors.As(err, &execErr) {\n    // a field was missing on the values struct; execErr.Name identifies the failing node\n}","tryCatchPattern":"buf, err := util.ParseTemplate(nerdctlScript, values)\nif err != nil {\n    var execErr template.ExecError\n    if errors.As(err, &execErr) {\n        return fmt.Errorf(\"nerdctl template references unknown field in %q\", execErr.Name)\n    }\n    return fmt.Errorf(\"error applying nerdctl script template: %w\", err)\n}","preventionTips":["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"],"tags":["go","colima","nerdctl","template","internal"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}