From 806d787369b8f183d4fe1c267ec82a4b9916604f Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Tue, 29 Oct 2024 14:08:49 +0300 Subject: [PATCH] fix: don't panic in cli logs (#5983) * fix: don't panic in cli logs Signed-off-by: Vladislav Sukhin * fix: remove debug printing Signed-off-by: Vladislav Sukhin --------- Signed-off-by: Vladislav Sukhin --- .../commands/testworkflows/run.go | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index b390466adc..d0f10c51ba 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -340,7 +340,7 @@ func printRawLogLines(logs []byte, steps []testkube.TestWorkflowSignature, resul logs = nil } else { line = string(logs[:newLineIndex]) - logs = logs[newLineIndex+1:] + logs = logs[newLineIndex+len(NL):] } line = trimTimestamp(line) @@ -354,28 +354,34 @@ func printRawLogLines(logs []byte, steps []testkube.TestWorkflowSignature, resul nextRef := start[1] - for i == -1 || steps[i].Ref != nextRef { + for i == -1 || (i < len(steps) && steps[i].Ref != nextRef) { if ps, ok := results[currentRef]; ok && ps.Status != nil { took := ps.FinishedAt.Sub(ps.QueuedAt).Round(time.Millisecond) - printStatus(steps[i], *ps.Status, took, i, len(steps), steps[i].Label()) + if i != -1 { + printStatus(steps[i], *ps.Status, took, i, len(steps), steps[i].Label()) + } } i++ - currentRef = steps[i].Ref - printStatusHeader(i, len(steps), steps[i].Label()) + if i < len(steps) { + currentRef = steps[i].Ref + printStatusHeader(i, len(steps), steps[i].Label()) + } } } - for _, step := range steps[i:] { - if ps, ok := results[currentRef]; ok && ps.Status != nil { - took := ps.FinishedAt.Sub(ps.QueuedAt).Round(time.Millisecond) - printStatus(step, *ps.Status, took, i, len(steps), steps[i].Label()) - } + if i != -1 && i < len(steps) { + for _, step := range steps[i:] { + if ps, ok := results[currentRef]; ok && ps.Status != nil { + took := ps.FinishedAt.Sub(ps.QueuedAt).Round(time.Millisecond) + printStatus(step, *ps.Status, took, i, len(steps), steps[i].Label()) + } - i++ - currentRef = step.Ref - if i < len(steps) { - printStatusHeader(i, len(steps), steps[i].Label()) + i++ + currentRef = step.Ref + if i < len(steps) { + printStatusHeader(i, len(steps), steps[i].Label()) + } } } }