From 40549e11320ce5cb72bdbd57964e12919c1caf01 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Mon, 24 Jul 2023 10:32:10 +0100 Subject: [PATCH] check in stderrFrame is nil before logging stderrFrame.Data (#17815) (#18041) Co-authored-by: Kevin Mulvey --- .changelog/17815.txt | 3 +++ command/alloc_logs.go | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changelog/17815.txt diff --git a/.changelog/17815.txt b/.changelog/17815.txt new file mode 100644 index 000000000..369dca130 --- /dev/null +++ b/.changelog/17815.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Fix panic in `alloc logs` command when receiving empty stdout or stderr log frames +``` diff --git a/command/alloc_logs.go b/command/alloc_logs.go index 03d16174c..901dd2d4b 100644 --- a/command/alloc_logs.go +++ b/command/alloc_logs.go @@ -397,11 +397,15 @@ func (l *AllocLogsCommand) tailMultipleFiles(client *api.Client, alloc *api.Allo case stdoutErr := <-stdoutErrCh: return fmt.Errorf("received an error from stdout log stream: %v", stdoutErr) case stdoutFrame := <-stdoutFrames: - logUI.Output(string(stdoutFrame.Data)) + if stdoutFrame != nil { + logUI.Output(string(stdoutFrame.Data)) + } case stderrErr := <-stderrErrCh: return fmt.Errorf("received an error from stderr log stream: %v", stderrErr) case stderrFrame := <-stderrFrames: - logUI.Warn(string(stderrFrame.Data)) + if stderrFrame != nil { + logUI.Warn(string(stderrFrame.Data)) + } } } }