From f3fa1a5d8915b87d17569fbe8dcda1be8b4acd9f Mon Sep 17 00:00:00 2001 From: shireenf-ibm Date: Thu, 12 Oct 2023 14:03:46 +0300 Subject: [PATCH 1/3] returning an err string describing the go generated error instead of returning the original error --- pkg/netpol/diff/diff_test.go | 2 +- pkg/netpol/scan/error_types.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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..bc889b96 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} } From 8d7090eff21de8aa40edcb8081466b2b551627ae Mon Sep 17 00:00:00 2001 From: shireenf-ibm <82180114+shireenf-ibm@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:53:06 +0300 Subject: [PATCH 2/3] Update pkg/netpol/scan/error_types.go Co-authored-by: Adi Sosnovich <82078442+adisos@users.noreply.github.com> --- pkg/netpol/scan/error_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/netpol/scan/error_types.go b/pkg/netpol/scan/error_types.go index bc889b96..65b04597 100644 --- a/pkg/netpol/scan/error_types.go +++ b/pkg/netpol/scan/error_types.go @@ -101,7 +101,7 @@ func (err *FailedReadingFileError) Unwrap() error { func (err *FailedAccessingDirError) Error() string { if errors.Is(err.origErr, os.ErrNotExist) { - return fmt.Sprintf("directory: <%s> was not found", err.dirPath) + return fmt.Sprintf("directory %s was not found", err.dirPath) } return fmt.Sprintf("failed reading contents of directory: <%s> ", err.dirPath) From 73e641d4ec13aec3ea8bbee2873bf948c5c8a945 Mon Sep 17 00:00:00 2001 From: shireenf-ibm <82180114+shireenf-ibm@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:53:12 +0300 Subject: [PATCH 3/3] Update pkg/netpol/scan/error_types.go Co-authored-by: Adi Sosnovich <82078442+adisos@users.noreply.github.com> --- pkg/netpol/scan/error_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/netpol/scan/error_types.go b/pkg/netpol/scan/error_types.go index 65b04597..c4a076c1 100644 --- a/pkg/netpol/scan/error_types.go +++ b/pkg/netpol/scan/error_types.go @@ -104,7 +104,7 @@ func (err *FailedAccessingDirError) Error() string { return fmt.Sprintf("directory %s was not found", err.dirPath) } - return fmt.Sprintf("failed reading contents of directory: <%s> ", err.dirPath) + return fmt.Sprintf("failed reading contents of directory %s ", err.dirPath) } func (err *FailedAccessingDirError) Unwrap() error {