{"record":{"id":"4429266797963913","repo":"abiosoft/colima","slug":"error-parsing-disk-mount-script-template-v","errorCode":null,"errorMessage":"error parsing disk mount script template: %v","messagePattern":"error parsing disk mount script template: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"environment/vm/lima/disk.go","lineNumber":107,"sourceCode":"\t\treturn incus.DataDisk()\n\t}\n\n\treturn environment.DataDisk{}\n}\n\nfunc diskMountScript(format bool) string {\n\tvar values = struct {\n\t\tFormat     bool\n\t\tInstanceId string\n\t}{\n\t\tFormat:     format,\n\t\tInstanceId: config.CurrentProfile().ID,\n\t}\n\n\tb, err := util.ParseTemplate(diskScript, values)\n\tif err != nil {\n\t\t// must never happen\n\t\tpanic(fmt.Sprintf(\"error parsing disk mount script template: %v\", err))\n\t}\n\treturn string(b)\n}\n\nfunc (l *limaVM) mountRuntimeDisk(conf config.Config, format bool) {\n\t// provision script to prepare disk\n\tl.limaConf.Provision = append(l.limaConf.Provision, limaconfig.Provision{\n\t\tMode:   \"dependency\",\n\t\tScript: diskMountScript(format),\n\t})\n\n\t// handle disk mounts\n\tdisk := dataDisk(conf.Runtime)\n\n\t// pre mount script\n\tfor _, script := range disk.PreMount {\n\t\tl.limaConf.Provision = append(l.limaConf.Provision, limaconfig.Provision{\n\t\t\tMode:   \"dependency\",","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/vm/lima/disk.go#L89-L125","documentation":"diskMountScript (environment/vm/lima/disk.go:107) parses the hardcoded diskScript template with a fixed values struct {Format bool, InstanceId string}; if ParseTemplate returns any error it panics with this message ('must never happen'). Because both the template body and the values are compile-time constants in the same file, the only way to reach the panic is a source edit that breaks the template (syntax error) or references a field absent from the values struct. It crashes the CLI at VM startup whenever a runtime disk is provisioned.","triggerScenarios":"Editing the diskScript template literal in environment/vm/lima/disk.go and introducing a typo ({{.format}} instead of {{.Format}}, missing braces), then running `colima start` with a disk configured — the panic fires while generating the Lima provision script.","commonSituations":"Fork development around disk mounting; renaming config fields without updating the template; build from a dirty tree mid-refactor.","solutions":["Fix the template literal in disk.go: match field names exactly (Format, InstanceId) and balance delimiters","Add a unit test that calls diskMountScript(true) and diskMountScript(false) and asserts no panic and non-empty output","Run `go test ./environment/...` after touching templates before starting a VM","If hit on a stock binary, reinstall — it means the binary does not match the sources"],"exampleFix":"// environment/vm/lima/disk.go (before)\nconst diskScript = `echo {{.format}} {{.InstanceId}}` // .format -> execute error -> panic\n\n// after\nconst diskScript = `echo {{.Format}} {{.InstanceId}}`","handlingStrategy":"try-catch","validationCode":"// fork safety net: validate the disk template at init/test time\nfunc init() {\n    if _, err := util.ParseTemplate(diskScript, struct {\n        Format     bool\n        InstanceId string\n    }{true, \"test\"}); err != nil {\n        panic(\"diskScript template is broken: \" + err.Error())\n    }\n}","typeGuard":null,"tryCatchPattern":"// if you call code that may panic during template generation:\ndefer func() {\n    if r := recover(); r != nil {\n        return fmt.Errorf(\"disk mount script generation failed: %v\", r)\n    }\n}()","preventionTips":["Unit-test diskMountScript(true) and diskMountScript(false) after any template edit","Keep template field names in lockstep with the values struct","Run `go test ./environment/vm/lima/...` before starting a VM in dev builds","Never ship a dev-built binary without the template tests passing"],"tags":["template","panic","disk","lima"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}