{"record":{"id":"9df089eef787d58e","repo":"abiosoft/colima","slug":"not-running","errorCode":null,"errorMessage":"not running","messagePattern":"not running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/vm/lima/lima.go","lineNumber":279,"sourceCode":"\n\t// minor delay to prevent possible race condition.\n\ttime.Sleep(time.Second * 2)\n\n\tif err := l.Start(ctx, l.conf); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc (l limaVM) Host() environment.HostActions {\n\treturn l.host\n}\n\nfunc (l limaVM) Env(s string) (string, error) {\n\tctx := context.Background()\n\tif !l.Running(ctx) {\n\t\treturn \"\", fmt.Errorf(\"not running\")\n\t}\n\treturn l.RunOutput(\"echo\", \"$\"+s)\n}\n\nfunc (l limaVM) Created() bool {\n\tstat, err := os.Stat(config.CurrentProfile().LimaFile())\n\treturn err == nil && !stat.IsDir()\n}\n\nfunc (l limaVM) User() (string, error) {\n\treturn l.RunOutput(\"whoami\")\n}\n\nfunc (l limaVM) Arch() environment.Arch {\n\ta, _ := l.RunOutput(\"uname\", \"-m\")\n\treturn environment.Arch(a)\n}\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/vm/lima/lima.go#L261-L297","documentation":"limaVM.Env returns the value of an environment variable from inside the guest by first checking l.Running(ctx) (a state query against the Lima instance) and then echoing the variable over SSH. If the VM is not in a running state, the call short-circuits with the bare error 'not running' before touching the guest. This is a state precondition failure, not an execution failure.","triggerScenarios":"Calling Env while the VM is stopped, starting, or stopping; calling immediately after Start returns but before Lima reports the running state; a crashed VM whose state query reports non-running. Note Running uses a background context internally so it cannot be cancelled by the caller.","commonSituations":"Automation that queries guest env vars right after start commands (boot race); scripts running against a profile the user stopped; daemon code polling guest env on a deleted instance.","solutions":["Guard the call with `if !vm.Running(ctx) { start or wait }` before requesting Env.","Retry with backoff for a few seconds after Start to let Lima's state settle.","Check `colima status` in scripts before querying guest environment details.","Handle the 'not running' error string explicitly in callers to distinguish it from SSH failures."],"exampleFix":"// before\nval, err := vm.Env(\"DOCKER_HOST\") // may error 'not running'\n\n// after\nif !vm.Running(ctx) {\n    return fmt.Errorf(\"vm not running; start before reading env\")\n}\nval, err := vm.Env(\"DOCKER_HOST\")","handlingStrategy":"validation","validationCode":"if !vm.Running(ctx) {\n    return fmt.Errorf(\"cannot read guest env: VM not running\")\n}\nval, err := vm.Env(\"DOCKER_HOST\")","typeGuard":null,"tryCatchPattern":"Go: on err != nil, if err.Error() == \"not running\" handle by starting/waiting instead of reporting an execution failure.","preventionTips":["Check colima status before querying guest env","Add short backoff after Start before env queries","Handle the literal 'not running' error distinctly"],"tags":["lifecycle","state","guest","environment-variables","colima"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}