Skip to content

Commit

Permalink
Fix almost empty error when wsl.exe fails.
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.
  • Loading branch information
CarlosNihelton committed Sep 6, 2024
1 parent bcd2165 commit dc1fd28
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 dc1fd28

Please sign in to comment.