{"record":{"id":"b0ae1fc1b24d276d","repo":"lima-vm/lima","slug":"failed-to-read-instance-state-for-instance-q-tr","errorCode":null,"errorMessage":"failed to read instance state for instance %#q, try running `wsl --list --verbose` to debug, err: %w","messagePattern":"failed to read instance state for instance %#q, try running `wsl --list --verbose` to debug, err: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/wsl2/vm_windows.go","lineNumber":220,"sourceCode":"// (3) Expected output when no distros are installed, and WSL2 has no kernel installed:\n//\n// PS > wsl --list --verbose\n// Windows Subsystem for Linux has no installed distributions.\n// Distributions can be installed by visiting the Microsoft Store:\n// https://aka.ms/wslstore\nfunc getWslStatus(ctx context.Context, instName string) (string, error) {\n\tdistroName := \"lima-\" + instName\n\tout, err := executil.RunUTF16leCommand([]string{\n\t\t\"wsl.exe\",\n\t\t\"--list\",\n\t\t\"--verbose\",\n\t}, executil.WithContext(ctx))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to run `wsl --list --verbose`, err: %w (out=%#q)\", err, out)\n\t}\n\n\tif out == \"\" {\n\t\treturn limatype.StatusBroken, fmt.Errorf(\"failed to read instance state for instance %#q, try running `wsl --list --verbose` to debug, err: %w\", instName, err)\n\t}\n\n\t// Check for edge cases first\n\tif strings.Contains(out, \"Windows Subsystem for Linux has no installed distributions.\") {\n\t\tif strings.Contains(out, \"Wsl/WSL_E_DEFAULT_DISTRO_NOT_FOUND\") {\n\t\t\treturn limatype.StatusBroken, fmt.Errorf(\n\t\t\t\t\"failed to read instance state for instance %#q because no distro is installed,\"+\n\t\t\t\t\t\"try running `wsl --install -d Ubuntu` and then re-running Lima\", instName)\n\t\t}\n\t\treturn limatype.StatusBroken, fmt.Errorf(\n\t\t\t\"failed to read instance state for instance %#q because there is no WSL kernel installed,\"+\n\t\t\t\t\"this usually happens when WSL was installed for another user, but never for your user.\"+\n\t\t\t\t\"Try running `wsl --install -d Ubuntu` and `wsl --update`, and then re-running Lima\", instName)\n\t}\n\n\tvar instState string\n\twslListColsRegex := regexp.MustCompile(`\\s+`)\n\t// wsl --list --verbose may have different headers depending on localization, just split by line","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/wsl2/vm_windows.go#L202-L238","documentation":"After `wsl --list --verbose` succeeds, if its output is empty Lima cannot determine the instance state and reports the instance as StatusBroken. This also happens when err was non-nil but out was empty, so the wrapped err is often a nil-interface artifact.","triggerScenarios":"getWslStatus receives out == \"\" from a successful (or vacuously failing) `wsl --list --verbose` run — no distro listing could be parsed.","commonSituations":"WSL installed but no distributions registered; wsl.exe emitting only a warning line; WSL in a partially installed state producing no listing; older WSL versions with different output encodings.","solutions":["Run `wsl --list --verbose` manually to confirm output","If no distros exist, install one (`wsl --install -d Ubuntu`) and re-run Lima","Update WSL (`wsl --update`) to get consistent UTF-16le output","Recreate the instance with `limactl start` once WSL lists correctly"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Ensure at least one distro exists and listing is non-empty\nconst out = execSync('wsl.exe --list --verbose').toString('utf16le').trim();\nif (!out) throw new Error('wsl --list --verbose returned nothing; reinstall WSL');","typeGuard":"function isBrokenStateQuery(e) { return /failed to read instance state/.test(String(e)); }","tryCatchPattern":"try {\n  const st = await limactlInspect(inst);\n} catch (e) {\n  if (/failed to read instance state/.test(String(e))) {\n    // treat instance as broken; offer recreate path\n    console.warn('Instance state unreadable; run limactl delete and start fresh');\n  } else throw e;\n}","preventionTips":["Never leave a Windows user profile with zero WSL distros","Update WSL so `--list --verbose` always emits parseable UTF-16le output","After WSL reinstall, recreate Lima instances rather than reusing broken state"],"tags":["wsl2","state-detection","empty-output"],"backgroundTag":"wsl-command-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}