cmd/bench: try to print results even if there's an error running sweet

Currently if sweet fails partway through, we lose any results it
generated. Instead, try to dump results and overwrite whatever errors
are encountered with a sweet error, if there was one.

Change-Id: I934b41144bb67e169074cdf484b0f4e2609c6a8e
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/384515
Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/cmd/bench/sweet.go b/cmd/bench/sweet.go
index 04d5d93..a021792 100644
--- a/cmd/bench/sweet.go
+++ b/cmd/bench/sweet.go
@@ -114,9 +114,19 @@
 	)
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
-	if err := cmd.Run(); err != nil {
-		return fmt.Errorf("error running sweet run: %w", err)
-	}
+
+	// Don't fail immediately. Let's try to dump whatever results we have first.
+	sweetErr := cmd.Run()
+	defer func() {
+		// Any sweet errors take precendence over errors encountered in printing
+		// results.
+		if sweetErr != nil {
+			if err != nil {
+				log.Printf("error dumping results: %v", err)
+			}
+			err = fmt.Errorf("error running sweet run: %w", sweetErr)
+		}
+	}()
 
 	// Dump results to stdout.
 	for _, tc := range tcs {