Skip to content

Commit

Permalink
Print data collection errors at the end
Browse files Browse the repository at this point in the history
Easier to read than when interleaved with dots that denote progress.
  • Loading branch information
rhcarvalho committed Sep 16, 2016
1 parent d53224c commit 051ac43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ func main() {
runner := NewDumpRunner(basePath)

log.Print("Collecting system information...")
RunAllDumpTasks(runner, basePath, *concurrentTasks, fileOnlyLogger)
errs := RunAllDumpTasks(runner, basePath, *concurrentTasks, os.Stderr)

for _, err := range errs {
if ierr, ok := err.(IgnorableError); ok && ierr.Ignore() {
fileOnlyLogger.Printf("Task error: %v", err)
continue
}
// TODO: there should be a way to identify which task
// had an error.
log.Printf("Task error: %v", err)
}

log.Print("Analyzing data...")
analysisResults := RunAllAnalysisTasks(runner, basePath, *concurrentTasks)
Expand Down
26 changes: 12 additions & 14 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
Expand All @@ -19,9 +20,12 @@ type Logger interface {
Printf(format string, v ...interface{})
}

// RunAllDumpTasks runs all tasks known to the dump tool using concurrent workers.
// Dump output goes to path.
func RunAllDumpTasks(runner Runner, path string, workers int, fileOnlyLogger Logger) {
// RunAllDumpTasks runs all tasks known to the dump tool using concurrent
// workers and returns task errors. Dump output goes to path. Progress is
// communicated by writing to out.
func RunAllDumpTasks(runner Runner, path string, workers int, out io.Writer) []error {
var errs []error

tasks := GetAllDumpTasks(runner, path)
results := make(chan error)

Expand All @@ -46,19 +50,13 @@ func RunAllDumpTasks(runner Runner, path string, workers int, fileOnlyLogger Log
// Loop through the task execution results and log errors.
for err := range results {
if err != nil {
if ierr, ok := err.(IgnorableError); ok && ierr.Ignore() {
fileOnlyLogger.Printf("Task error: %v", err)
continue
}
// TODO: there should be a way to identify which task
// had an error.
fmt.Fprintln(os.Stderr)
log.Printf("Task error: %v", err)
continue
errs = append(errs, err)
}
fmt.Fprint(os.Stderr, ".")
fmt.Fprint(out, ".")
}
fmt.Fprintln(os.Stderr)
fmt.Fprintln(out)

return errs
}

// GetAllDumpTasks returns a channel of all tasks known to the dump tool. It returns
Expand Down

0 comments on commit 051ac43

Please sign in to comment.