Skip to content

Commit 044f1af

Browse files
committed
repl: Print stdout/stderr on goimports error
If the program exits with a non-zero return code, the only info you get is "exit status 2", which is unhelpful at determining what went wrong.
1 parent e856a16 commit 044f1af

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/repl/repl.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"flag"
66
"fmt"
7+
"io"
78
"io/ioutil"
89
"os"
910
"os/exec"
@@ -349,9 +350,14 @@ func (s *Session) Eval(in string) (string, error, bytes.Buffer) {
349350
}
350351
f.Close()
351352

353+
b := new(bytes.Buffer)
352354
cmd := exec.Command("goimports", "-w", string(filepath.Dir(s.FilePath))+"/func_proxy.go")
355+
cmd.Stdout = b
356+
cmd.Stderr = b
353357
err = cmd.Run()
354358
if err != nil {
359+
os.Stderr.WriteString("Error running goimports:\n")
360+
io.Copy(os.Stderr, b)
355361
panic(err)
356362
}
357363

0 commit comments

Comments
 (0)