Skip to content

Commit

Permalink
Add new error code (#199)
Browse files Browse the repository at this point in the history
add new error code

---------

Co-authored-by: Vishal Kadam <vishalkadam@microsoft.com>
  • Loading branch information
vishal-kadam and Vishal Kadam committed Aug 24, 2023
1 parent 318b9be commit d330afc
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ var (
Unknown error = errors.New("Unknown Reason")
DeleteFailed error = errors.New("Delete Failed")
DeletePending error = errors.New("Delete Pending")
FileNotFound error = errors.New("The system cannot find the file specified")
PathNotFound error = errors.New("The system cannot find the path specified")
NotEnoughSpace error = errors.New("There is not enough space on the disk")
AccessDenied error = errors.New("Access is denied")
)

func GetErrorCode(err error) string {
if IsNotFound(err) {
if IsNotFound(err) || IsFileNotFound(err) || IsPathNotFound(err) {
return "NotFound"
} else if IsDegraded(err) {
return "Degraded"
Expand Down Expand Up @@ -80,7 +84,7 @@ func GetErrorCode(err error) string {
return "InvalidVersion"
} else if IsOldVersion(err) {
return "OldVersion"
} else if IsOutOfCapacity(err) {
} else if IsOutOfCapacity(err) || IsNotEnoughSpace(err) {
return "OutOfCapacity"
} else if IsOutOfNodeCapacity(err) {
return "OutOfNodeCapacity"
Expand Down Expand Up @@ -124,6 +128,8 @@ func GetErrorCode(err error) string {
return "Delete Pending"
} else if IsRunCommandFailed(err) {
return "RunCommandFailed"
} else if IsAccessDenied(err) {
return "AccessDenied"
}

// We dont know the type of error.
Expand Down Expand Up @@ -304,6 +310,22 @@ func IsRunCommandFailed(err error) bool {
return checkError(err, RunCommandFailed)
}

func IsFileNotFound(err error) bool {
return checkError(err, FileNotFound)
}

func IsPathNotFound(err error) bool {
return checkError(err, PathNotFound)
}

func IsNotEnoughSpace(err error) bool {
return checkError(err, NotEnoughSpace)
}

func IsAccessDenied(err error) bool {
return checkError(err, AccessDenied)
}

func checkError(wrappedError, err error) bool {
if wrappedError == nil {
return false
Expand All @@ -322,12 +344,13 @@ func checkError(wrappedError, err error) bool {

// Post this, this is a GRPC unknown error
// Try to parse the Message and match the error
if strings.Contains(wrappedError.Error(), err.Error()) {
wrappedErrorLowercase := strings.ToLower(wrappedError.Error())
errLowercase := strings.ToLower(err.Error())
if strings.Contains(wrappedErrorLowercase, errLowercase) {
return true
}

return false

}

func New(errString string) error {
Expand Down

0 comments on commit d330afc

Please sign in to comment.