Skip to content

Commit

Permalink
avoid printing redundant exit code error on test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mitranim committed Sep 26, 2022
1 parent 11705eb commit 2cffced
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions gow_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Go Watch: missing watch mode for the "go" command. Invoked exactly like the
package main

import (
e "errors"
l "log"
"os"
"os/exec"
Expand Down Expand Up @@ -159,7 +158,7 @@ func (self *Main) CmdWait(cmd *exec.Cmd) {
if err != nil {
// `go run` reports the program's exit code to stderr.
// In this case we suppress the error message to avoid redundancy.
if !(gg.Head(self.Opt.Args) == `run` && e.As(err, new(*exec.ExitError))) {
if !self.Opt.SkipErr(err) {
log.Println(`subcommand error:`, err)
}
} else if self.Opt.Verb {
Expand Down
4 changes: 2 additions & 2 deletions gow_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func withNewline[A ~string](val A) A {
return val + A(gg.Newline)
}

// The field is private to avoid accidental cyclic walking by pretty-printing
// tools, not for pointless "encapsulation".
// The field is private to avoid accidental cyclic walking by reflection-based
// code, not for pointless "encapsulation".
type Mained struct{ main *Main }

func (self *Mained) Init(val *Main) { self.main = val }
Expand Down
6 changes: 6 additions & 0 deletions gow_opt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
e "errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -122,3 +123,8 @@ func (self Opt) ShouldRestart(event FsEvent) bool {
path := event.Path()
return self.IgnoredPaths.Allow(path) && self.Extensions.Allow(path)
}

func (self Opt) SkipErr(err error) bool {
head := gg.Head(self.Args)
return (head == `run` || head == `test`) && e.As(err, new(*exec.ExitError))
}
11 changes: 3 additions & 8 deletions gow_stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ import (

type Stdio struct {
Mained
Buf []byte
Buf [1]byte
LastChar byte
LastInst time.Time
}

func (self *Stdio) Init(main *Main) {
self.Mained.Init(main)
self.Buf = make([]byte, 1)
}

/**
Doesn't require special cleanup before stopping `gow`. We run only one stdio
loop, without ever replacing it.
Expand All @@ -39,7 +34,7 @@ func (self *Stdio) Run() {
self.LastInst = time.Now()

for {
size, err := os.Stdin.Read(self.Buf)
size, err := os.Stdin.Read((&self.Buf)[:])
if err != nil || size == 0 {
return
}
Expand Down Expand Up @@ -110,7 +105,7 @@ func (self *Stdio) OnByteAny(char byte) {
main.Cmd.WriteChar(char)

if main.Opt.RawEcho {
gg.Nop2(os.Stdout.Write(self.Buf))
gg.Nop2(os.Stdout.Write(self.Buf[:]))
}
}

Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ Currently requires Unix (MacOS, Linux, BSD). On Windows, runs under WSL.

Why not other runners, general-purpose watchers, etc:

* Has hotkeys!
* Has hotkeys, such as `ctrl+r` to restart!
* Go-specific, easy to remember.
* Ignores non-Go files by default.
* Better watcher: recursive, no delays, no polling; uses https://github.com/rjeczalik/notify.
* Silent by default.
* No garbage files.
* Can properly clear the terminal on restart.
* Does not leak subprocesses.
* Minimal dependencies.

## Installation
Expand Down

0 comments on commit 2cffced

Please sign in to comment.