Skip to content

Commit

Permalink
Logs errors when redactors error since they get swallowed
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Sep 14, 2023
1 parent 49f3ef3 commit 0298f96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/collect/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r CollectorResult) SaveResult(bundlePath string, relativePath string, read
return errors.Wrap(err, "failed to stat file")
}

klog.V(2).Infof("Added %q (%d MB) to bundle output", relativePath, fileInfo.Size()/(1024*1024))
klog.V(2).Infof("Added %q (%d KB) to bundle output", relativePath, fileInfo.Size()/(1024))
return nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/redact/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package redact
import (
"bufio"
"bytes"
"fmt"
"io"

"github.com/replicatedhq/troubleshoot/pkg/constants"
"k8s.io/klog/v2"
)

type literalRedactor struct {
Expand All @@ -29,9 +31,15 @@ func (r literalRedactor) Redact(input io.Reader, path string) io.Reader {
go func() {
var err error
defer func() {
if err == io.EOF {
if err == nil || err == io.EOF {
writer.Close()
} else {
if err == bufio.ErrTooLong {
s := fmt.Sprintf("Error redacting %q. A line in the file exceeded %d MB max length", path, constants.SCANNER_MAX_SIZE/1024/1024)
klog.V(2).Info(s)
} else {
klog.V(2).Info(fmt.Sprintf("Error redacting %q: %v", path, err))
}
writer.CloseWithError(err)
}
}()
Expand Down
10 changes: 9 additions & 1 deletion pkg/redact/single_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package redact
import (
"bufio"
"bytes"
"fmt"
"io"
"regexp"

"github.com/replicatedhq/troubleshoot/pkg/constants"
"k8s.io/klog/v2"
)

type SingleLineRedactor struct {
Expand Down Expand Up @@ -41,9 +43,15 @@ func (r *SingleLineRedactor) Redact(input io.Reader, path string) io.Reader {
go func() {
var err error
defer func() {
if err == io.EOF {
if err == nil || err == io.EOF {
writer.Close()
} else {
if err == bufio.ErrTooLong {
s := fmt.Sprintf("Error redacting %q. A line in the file exceeded %d MB max length", path, constants.SCANNER_MAX_SIZE/1024/1024)
klog.V(2).Info(s)
} else {
klog.V(2).Info(fmt.Sprintf("Error redacting %q: %v", path, err))
}
writer.CloseWithError(err)
}
}()
Expand Down

0 comments on commit 0298f96

Please sign in to comment.