{"record":{"id":"b5f428226086fad9","repo":"lima-vm/lima","slug":"failed-to-convert-output-from-utf16-when-running-c","errorCode":null,"errorMessage":"failed to convert output from UTF16 when running command %v, err: %w","messagePattern":"failed to convert output from UTF16 when running command (.+?), err: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/executil/command.go","lineNumber":49,"sourceCode":"\tfor _, f := range opts {\n\t\tif err := f(&o); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tvar cmd *exec.Cmd\n\tctx := o.ctx\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\tcmd = exec.CommandContext(ctx, args[0], args[1:]...)\n\n\toutString := \"\"\n\tout, err := cmd.CombinedOutput()\n\tif out != nil {\n\t\ts, err := strutil.FromUTF16leToString(bytes.NewReader(out))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to convert output from UTF16 when running command %v, err: %w\", args, err)\n\t\t}\n\t\toutString = s\n\t}\n\treturn outString, err\n}\n","sourceCodeStart":31,"sourceCodeEnd":55,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/executil/command.go#L31-L55","documentation":"RunUTF16leCommand runs a command (typically Windows wsl.exe, which emits UTF-16LE output) and converts the combined output from UTF-16LE to a Go string; this error wraps the conversion failure from strutil.FromUTF16leToString. It indicates the command's output was not valid UTF-16LE, so it cannot be decoded.","triggerScenarios":"Calling RunUTF16leCommand (used by startVM, initVM, stopVM, unregisterVM, getWslStatus) when the executed command's output is not valid UTF-16LE — e.g. an odd byte count or malformed surrogate pairs in the combined output.","commonSituations":"wsl.exe emitting localized/odd-encoded output on some Windows configurations; the command writing binary or plain-ASCII error output instead of UTF-16; a corrupted or legacy code page in the Windows console.","solutions":["Inspect the wrapped conversion error to see the malformed byte issue","Run the underlying WSL command manually (e.g. `wsl.exe --status`) to inspect its raw output encoding","Ensure Windows console code page/locales are standard (chcp 65001) and wsl.exe is up to date (`wsl --update`)","Check that the command isn't failing and emitting non-UTF16 error text; handle err from cmd execution separately"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify wsl.exe is present and produces output before relying on it\nif _, err := exec.LookPath(\"wsl.exe\"); err != nil {\n    return errors.New(\"wsl.exe not available\")\n}","typeGuard":null,"tryCatchPattern":"out, err := executil.RunUTF16leCommand(ctx, args...)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to convert output from UTF16\") {\n        // fall back to raw output / log for diagnosis\n        log.Warnf(\"non-UTF16 output from wsl: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep wsl.exe updated (wsl --update)","Avoid custom console code pages that alter output encoding","Handle command failures before decoding output","Test on target Windows locales"],"tags":["windows","wsl","encoding","utf16"],"backgroundTag":"utf16-decode-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}