Only log the errors from observers

Because we call the observers concurrently, we must not write to S.err
inside the goroutines.  For now, we simply log an error from an
observer.
This commit is contained in:
Özgür Kesim 2020-01-16 10:28:01 +01:00
parent 65a8d52b7a
commit 6eebe8c9f4

View File

@ -102,8 +102,7 @@ func (S *Scanner) OnFound(fun Observer) {
//
// Run will return an error if it couldn't read the proc filesystem. Otherwise
// it will try to continue to loop over all pids, writing potential errors to
// the console. Errors from the observer functions are also logged and the
// final such error is the return value of Run().
// the console. Errors from the observer functions are logged.
func (S *Scanner) Run() error {
if S.err != nil {
return S.err
@ -141,8 +140,8 @@ func (S *Scanner) Run() error {
go func() {
err = observer(pid, offset)
if err != nil {
S.setErrorf("S.observer[%d] error: %v", n, err)
// TODO: propagate errors from all Observers.
S.Printf("S.observer[%d](%d, %d) error: %v", n, pid, offset, err)
// TODO: accumulate errors from all Observers.
}
wg.Done()
}()