diff --git a/pkg/netpol/diff/diff_test.go b/pkg/netpol/diff/diff_test.go index 45fbfe4e..063fc493 100644 --- a/pkg/netpol/diff/diff_test.go +++ b/pkg/netpol/diff/diff_test.go @@ -377,7 +377,7 @@ func TestFatalErrors(t *testing.T) { name: "dir 1 does not exists", dir1: filepath.Join("bad_yamls", "subdir3"), dir2: "ipblockstest", - firstErrStr: "error accessing directory:", + firstErrStr: "was not found", }, { name: "dir 1 includes illegal pods list", diff --git a/pkg/netpol/scan/error_types.go b/pkg/netpol/scan/error_types.go index 49c64bcb..c4a076c1 100644 --- a/pkg/netpol/scan/error_types.go +++ b/pkg/netpol/scan/error_types.go @@ -3,6 +3,7 @@ package scan import ( "errors" "fmt" + "os" ) // FileProcessingError holds all information about a single error/warning that occurred during @@ -47,6 +48,7 @@ type FailedReadingFileError struct { type FailedAccessingDirError struct { origErr error + dirPath string } func (err *NoYamlsFoundError) Error() string { @@ -98,7 +100,11 @@ func (err *FailedReadingFileError) Unwrap() error { } func (err *FailedAccessingDirError) Error() string { - return fmt.Sprintf("error accessing directory: %v", err.origErr) + if errors.Is(err.origErr, os.ErrNotExist) { + return fmt.Sprintf("directory %s was not found", err.dirPath) + } + + return fmt.Sprintf("failed reading contents of directory %s ", err.dirPath) } func (err *FailedAccessingDirError) Unwrap() error { @@ -190,5 +196,5 @@ func failedReadingFile(filePath string, err error) *FileProcessingError { } func failedAccessingDir(dirPath string, err error, isSubDir bool) *FileProcessingError { - return &FileProcessingError{&FailedAccessingDirError{err}, dirPath, 0, -1, !isSubDir, true} + return &FileProcessingError{&FailedAccessingDirError{origErr: err, dirPath: dirPath}, dirPath, 0, -1, !isSubDir, true} }