Skip to content

Commit

Permalink
Merge pull request #29 from SimonRichardson/add-logging-for-non-fatal…
Browse files Browse the repository at this point in the history
…-errors

#29

To help diagnose issues when a runner restarts, log out all the errors not just the fatal ones.
  • Loading branch information
jujubot authored Aug 25, 2023
2 parents e43ac12 + a00cdc9 commit 516c426
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,11 @@ type panicError interface {
// to start. It maintains the runner.finalError field and
// restarts the worker if necessary.
func (runner *Runner) workerDone(info doneInfo) {
params := runner.params

workerInfo := runner.workers[info.id]
if !workerInfo.stopping && info.err == nil {
runner.params.Logger.Debugf("removing %q from known workers", info.id)
params.Logger.Debugf("removing %q from known workers", info.id)
runner.removeWorker(info.id, workerInfo.done)
return
}
Expand All @@ -465,9 +467,11 @@ func (runner *Runner) workerDone(info doneInfo) {
// Panics should always have the full stacktrace in the error log.
errStr = strings.Join(append([]string{errStr}, errWithStack.StackTrace()...), "\n")
}
if runner.params.IsFatal(info.err) {
runner.params.Logger.Errorf("fatal %q: %s", info.id, errStr)
if runner.finalError == nil || runner.params.MoreImportant(info.err, runner.finalError) {

params.Logger.Debugf("error %q: %s", info.id, errStr)
if params.IsFatal(info.err) {
params.Logger.Errorf("fatal error %q: %s", info.id, errStr)
if runner.finalError == nil || params.MoreImportant(info.err, runner.finalError) {
runner.finalError = info.err
}
runner.removeWorker(info.id, workerInfo.done)
Expand All @@ -476,24 +480,27 @@ func (runner *Runner) workerDone(info doneInfo) {
runner.killAll()
}
return
} else {
params.Logger.Infof("non-fatal error %q: %s", info.id, errStr)
}
if !runner.params.ShouldRestart(info.err) {
runner.params.Logger.Debugf("removing %q from known workers", info.id)

if !params.ShouldRestart(info.err) {
params.Logger.Debugf("removing %q from known workers", info.id)
runner.removeWorker(info.id, workerInfo.done)
return
}
runner.params.Logger.Errorf("exited %q: %s", info.id, errStr)
params.Logger.Errorf("exited %q: %s", info.id, errStr)
}
if workerInfo.start == nil {
runner.params.Logger.Debugf("no restart, removing %q from known workers", info.id)
params.Logger.Debugf("no restart, removing %q from known workers", info.id)

// The worker has been deliberately stopped;
// we can now remove it from the list of workers.
runner.removeWorker(info.id, workerInfo.done)
return
}
go runner.runWorker(workerInfo.restartDelay, info.id, workerInfo.start)
workerInfo.restartDelay = runner.params.RestartDelay
workerInfo.restartDelay = params.RestartDelay
}

// removeWorker removes the worker with the given id from the
Expand Down

0 comments on commit 516c426

Please sign in to comment.