Skip to content

Commit

Permalink
fix(backend): Almost empty error when wsl.exe fails. (#120)
Browse files Browse the repository at this point in the history
If wsl.exe doesn't exit 0, then we read the byte buffer to find
"Wsl/Service/WSL_E_DISTRO_NOT_FOUND".

By doing so we're exhausting the reader, so the last line of this
function essentially assembles an empty message, because there is
nothing more to retrieve from the reader.

The fix is write the buffer contents into strings and use those when
comparing and generating error messages.
That could be a problem for very long outputs, but wsl.exe itself always
generates short messages (currently at least).
  • Loading branch information
CarlosNihelton authored Sep 6, 2024
2 parents bcd2165 + dc1fd28 commit 049fd49
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/backend/windows/wslexe_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ func wslExe(ctx context.Context, args ...string) ([]byte, error) {
return stdout.Bytes(), nil
}

if strings.Contains(stdout.String(), "Wsl/Service/WSL_E_DISTRO_NOT_FOUND") {
out := stdout.String()
e := stderr.String()

if strings.Contains(out, "Wsl/Service/WSL_E_DISTRO_NOT_FOUND") {
return nil, ErrNotExist
}

if strings.Contains(stderr.String(), "Wsl/Service/WSL_E_DISTRO_NOT_FOUND") {
if strings.Contains(e, "Wsl/Service/WSL_E_DISTRO_NOT_FOUND") {
return nil, ErrNotExist
}

return nil, fmt.Errorf("%v. Stdout: %s. Stderr: %s", err, stdout.Bytes(), stderr.Bytes())
return nil, fmt.Errorf("%v. Stdout: %s. Stderr: %s", err, out, e)
}

0 comments on commit 049fd49

Please sign in to comment.