Catch previously undetected errors from git exit codes in async scans#1118
Conversation
Problem is that the clean filter will fail earlier because of corruption and this in turn fails the diff-index, which we now pick up. But this then fails ScanIndex which fsck treats as fatal instead of realising it's a symptom of something it can fix. Not sure how to handle this better yet
Reason is that although the first entry in the line is "(delete)", the check occurs on the result which only includes the SHAs; this is actually all zeroes in the delete case. This was silently failing before we error checked more rigorously.
| // stderr, _ := ioutil.ReadAll(cmd.Stderr) | ||
| // err := cmd.Wait() | ||
| // if err != nil { | ||
| // errchan <- fmt.Errorf("Error in git diff-index: %v %v", err, string(stderr)) |
There was a problem hiding this comment.
I'm not totally sure what to do about this yet, any ideas?
| for e := range w.errorChan { | ||
| if err != nil { | ||
| // Combine in case multiple errors | ||
| err = fmt.Errorf("%v\n%v", err, e) |
There was a problem hiding this comment.
This will lose the backtrace from any scans that return multiple errors. Any panics will show this as the culprit of the bug, and not a scanner that returns a channel wrapper. If it becomes a problem, I could see us using some MultiError type that preserves them, and teaching commands.Panic() how to handle it.
There was a problem hiding this comment.
True, I did consider pulling in https://github.com/hashicorp/go-multierror but thought it was overkill, and concentrated on making the error text itself return more useful info instead.
|
This looks good to me. 👍
What issues? Anything worth adding a test for? |
The main specific one was in Other issues were just clarifications really, most of all the prevalence of |
Fixes #1100 as well as surfacing a number of other fail states previously missed.
Wraps all scanner channels so that consumer only has to worry about primary results as channels, then check error result from
wrapper.Wait()at the end to pick up any bad exit conditions (rather than having to handle 2 channels themselves).Fixed a bunch of other issues while I was at it.