[cli] Don't print "a check failed" errors

Small improvement to the command-line output: skip printing "shac: a
check failed" when a check fails in an interactive session.

Change-Id: Ia85ef7ec6b0ebed10751e6cca705c5ae5a422aa7
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/860456
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Marc-Antoine Ruel <maruel@google.com>
diff --git a/main.go b/main.go
index 5a0245e..3509254 100644
--- a/main.go
+++ b/main.go
@@ -20,6 +20,7 @@
 	"fmt"
 	"os"
 
+	"github.com/mattn/go-isatty"
 	flag "github.com/spf13/pflag"
 	"go.fuchsia.dev/shac-project/shac/internal/cli"
 	"go.fuchsia.dev/shac-project/shac/internal/engine"
@@ -31,7 +32,14 @@
 		if errors.As(err, &stackerr) {
 			_, _ = os.Stderr.WriteString(stackerr.Backtrace())
 		}
-		_, _ = fmt.Fprintf(os.Stderr, "shac: %s\n", err)
+		// If a check failed and stderr is a terminal, appropriate information
+		// should have already been emitted by the reporter. If stderr is not a
+		// terminal then it may still be useful to print the "check failed"
+		// error message since the reporter output may not show up in the same
+		// stream as stderr.
+		if !errors.Is(err, engine.ErrCheckFailed) || !isatty.IsTerminal(os.Stderr.Fd()) {
+			_, _ = fmt.Fprintf(os.Stderr, "shac: %s\n", err)
+		}
 		os.Exit(1)
 	}
 }