Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplifying dir_not_exist error #249

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/netpol/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions pkg/netpol/scan/error_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scan
import (
"errors"
"fmt"
"os"
)

// FileProcessingError holds all information about a single error/warning that occurred during
Expand Down Expand Up @@ -47,6 +48,7 @@ type FailedReadingFileError struct {

type FailedAccessingDirError struct {
origErr error
dirPath string
}

func (err *NoYamlsFoundError) Error() string {
Expand Down Expand Up @@ -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)
shireenf-ibm marked this conversation as resolved.
Show resolved Hide resolved
}

return fmt.Sprintf("failed reading contents of directory: <%s> ", err.dirPath)
shireenf-ibm marked this conversation as resolved.
Show resolved Hide resolved
}

func (err *FailedAccessingDirError) Unwrap() error {
Expand Down Expand Up @@ -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}
}