pkg/eval: Fix EPIPE on Windows.

The syscall package exposes an EPIPE on Windows, but it's not what Windows APIs
return. The error number 232 is what is semantically EPIPE.
This commit is contained in:
Qi Xiao 2021-06-18 00:45:25 +01:00
parent 53dbece608
commit 6ced40733c
3 changed files with 18 additions and 2 deletions

View File

@ -6,7 +6,6 @@ import (
"io"
"os"
"sync"
"syscall"
"src.elv.sh/pkg/eval/errs"
"src.elv.sh/pkg/eval/vals"
@ -292,7 +291,7 @@ func (bo byteOutput) WriteString(s string) (int, error) {
func convertReaderGone(err error) error {
if pathErr, ok := err.(*os.PathError); ok {
if pathErr.Err == syscall.EPIPE {
if pathErr.Err == epipe {
return errs.ReaderGone{}
}
}

7
pkg/eval/port_unix.go Normal file
View File

@ -0,0 +1,7 @@
//+build !windows,!plan9,!js
package eval
import "syscall"
var epipe = syscall.EPIPE

10
pkg/eval/port_windows.go Normal file
View File

@ -0,0 +1,10 @@
package eval
import "syscall"
// Error number 232 is what Windows returns when trying to write on a pipe who
// reader has gone. The syscall package defines an EPIPE on Windows, but that's
// not what Windows API actually returns.
//
// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
var epipe = syscall.Errno(232)