diff --git a/pkg/util/util.go b/pkg/util/util.go index d40c7224e2d..b9022d331ca 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -490,9 +490,13 @@ func addFileToIgnoreFile(gitIgnoreFile, filename string, fs filesystem.Filesyste // DisplayLog displays logs to user stdout with some color formatting // numberOfLastLines limits the number of lines from the output when we are not following it // TODO(feloy) sync with devfile library? -func DisplayLog(followLog bool, rd io.ReadCloser, writer io.Writer, compName string, numberOfLastLines int) (err error) { +func DisplayLog(followLog bool, rd io.ReadCloser, writer io.Writer, compName string, numberOfLastLines int) error { - defer rd.Close() + defer func() { + if err := rd.Close(); err != nil { + klog.V(4).Infof("err occurred while closing resource: %v", err) + } + }() // Copy to stdout (in yellow) color.Set(color.FgYellow) @@ -510,14 +514,14 @@ func DisplayLog(followLog bool, rd io.ReadCloser, writer io.Writer, compName str os.Exit(1) }() - if _, err = io.Copy(writer, rd); err != nil { + if _, err := io.Copy(writer, rd); err != nil { return fmt.Errorf("error followLoging logs for %s: %w", compName, err) } } else if numberOfLastLines == -1 { // Copy to buffer (we aren't going to be followLoging the logs..) buf := new(bytes.Buffer) - _, err = io.Copy(buf, rd) + _, err := io.Copy(buf, rd) if err != nil { return fmt.Errorf("unable to copy followLog to buffer: %w", err) } @@ -554,7 +558,7 @@ func DisplayLog(followLog bool, rd io.ReadCloser, writer io.Writer, compName str } } } - return + return nil }