{"record":{"id":"3a61eddbd244664e","repo":"lima-vm/lima","slug":"failed-to-run-wsl-exe-unregister-s-w-out","errorCode":null,"errorMessage":"failed to run `wsl.exe --unregister %s`: %w (out=%#q)","messagePattern":"failed to run `wsl\\.exe --unregister (.+?)`: %w \\(out=%#q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/wsl2/vm_windows.go","lineNumber":175,"sourceCode":"\n\tgo func() {\n\t\tif err := keepAliveCmd.Run(); err != nil {\n\t\t\terrCh <- fmt.Errorf(\n\t\t\t\t\"error running wsl keepAlive command: %w\", err)\n\t\t}\n\t}()\n}\n\n// unregisterVM calls WSL to unregister a VM.\nfunc unregisterVM(ctx context.Context, distroName string) error {\n\tlogrus.Info(\"Unregistering WSL2 VM\")\n\tout, err := executil.RunUTF16leCommand([]string{\n\t\t\"wsl.exe\",\n\t\t\"--unregister\",\n\t\tdistroName,\n\t}, executil.WithContext(ctx))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to run `wsl.exe --unregister %s`: %w (out=%#q)\",\n\t\t\tdistroName, err, out)\n\t}\n\treturn nil\n}\n\n// GetWslStatus runs `wsl --list --verbose` and parses its output.\n// There are several possible outputs, all listed with their whitespace preserved output below.\n//\n// (1) Expected output if at least one distro is installed:\n// PS > wsl --list --verbose\n//\n//\tNAME      STATE           VERSION\n//\n// * Ubuntu    Stopped         2\n//\n// (2) Expected output when no distros are installed, but WSL is configured properly:\n// PS > wsl --list --verbose\n// Windows Subsystem for Linux has no installed distributions.","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/wsl2/vm_windows.go#L157-L193","documentation":"During instance deletion, Lima runs `wsl.exe --unregister <distroName>` to remove the underlying WSL distro. If wsl.exe fails (non-zero exit), Lima wraps the error plus output; the distro may still exist on disk.","triggerScenarios":"`limactl delete` calls unregisterVM; wsl.exe --unregister exits non-zero — distro name not found, distro currently running/locked, or wsl.exe itself fails to launch.","commonSituations":"Deleting an instance whose distro was already removed manually; distro still running so unregister is rejected; WSL not properly installed; corrupted WSL registration.","solutions":["Check the out= portion of the error for the specific wsl.exe message","Run `wsl --list --verbose`; if the distro is Running, stop it (`wsl -t <distroName>`) then retry `limactl delete`","If the distro no longer exists, the instance is already gone from WSL — remove stale Lima metadata with `limactl delete --force`","Run `wsl --update` and retry if wsl.exe itself is misbehaving"],"exampleFix":"// before\nlimactl delete myinstance            // fails: distro still running\n// after\nwsl -t lima-myinstance\nlimactl delete myinstance            // succeeds","handlingStrategy":"try-catch","validationCode":"// Check distro state before deleting\nconst list = execSync('wsl.exe --list --verbose').toString('utf16le');\nconst running = list.toLowerCase().includes('lima-' + inst) && /running/i.test(list);","typeGuard":"function isUnregisterError(e) { return String(e).includes('--unregister'); }","tryCatchPattern":"try {\n  await limactlDelete(inst);\n} catch (e) {\n  if (String(e).includes('--unregister')) {\n    try { execSync('wsl.exe -t lima-' + inst); } catch {}\n    await limactlDelete(inst); // retry after stopping distro\n  } else throw e;\n}","preventionTips":["Stop the instance (`limactl stop`) before deleting","Check `wsl --list --verbose` before manual unregister operations","Use `limactl delete --force` only after confirming WSL state"],"tags":["wsl2","unregister","instance-deletion"],"backgroundTag":"wsl-unregister-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}