From ca47fac476de618981d01fba24f3d3a6376c6479 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Sat, 4 Dec 2021 13:19:07 +0100 Subject: [PATCH] waitForLogs: enrich error with scanner error if any --- pkg/client/node.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/client/node.go b/pkg/client/node.go index 6925aed7d..f2e12a41e 100644 --- a/pkg/client/node.go +++ b/pkg/client/node.go @@ -745,6 +745,9 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node * }(ctx, runtime, node, since, donechan) + // pre-building error message in case the node stops returning logs for some reason: to be enriched with scanner error + errMsg := fmt.Errorf("error waiting for log line `%s` from node '%s': stopped returning log lines", message, node.Name) + // Start loop to check log stream for specified log message. // We're looping here, as sometimes the containers run into a crash loop, but *may* recover from that // e.g. when a new server is joining an existing cluster and has to wait for another member to finish learning. @@ -792,6 +795,10 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node * } + if e := scanner.Err(); e != nil { + errMsg = fmt.Errorf("%v: %w", errMsg, e) + } + out.Close() // no more input on scanner, but target log not yet found -> close current logreader (precautionary) // we got here, because the logstream ended (no more input on scanner), so we check if maybe the container crashed @@ -806,7 +813,7 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node * break } } - return fmt.Errorf("error waiting for log line `%s` from node '%s': stopped returning log lines", message, node.Name) + return errMsg } // NodeFilterByRoles filters a list of nodes by their roles