Add a isErr function to check for errs.

DisksInfo() should handle collection of some
base errors as offlineDisks.
This commit is contained in:
Harshavardhana 2017-01-02 10:43:56 -08:00
parent 6d10f4c19a
commit 7bbb532b4b
2 changed files with 17 additions and 3 deletions

View File

@ -121,12 +121,15 @@ func errorsCause(errs []error) []error {
return cerrs return cerrs
} }
var baseIgnoredErrs = []error{ // Collection of basic errors.
var baseErrs = []error{
errDiskNotFound, errDiskNotFound,
errFaultyDisk, errFaultyDisk,
errFaultyRemoteDisk, errFaultyRemoteDisk,
} }
var baseIgnoredErrs = baseErrs
// isErrIgnored returns whether given error is ignored or not. // isErrIgnored returns whether given error is ignored or not.
func isErrIgnored(err error, ignoredErrs ...error) bool { func isErrIgnored(err error, ignoredErrs ...error) bool {
err = errorCause(err) err = errorCause(err)
@ -137,3 +140,14 @@ func isErrIgnored(err error, ignoredErrs ...error) bool {
} }
return false return false
} }
// isErr returns whether given error is exact error.
func isErr(err error, errs ...error) bool {
err = errorCause(err)
for _, exactErr := range errs {
if err == exactErr {
return true
}
}
return false
}

View File

@ -169,10 +169,10 @@ func getDisksInfo(disks []StorageAPI) (disksInfo []disk.Info, onlineDisks int, o
info, err := storageDisk.DiskInfo() info, err := storageDisk.DiskInfo()
if err != nil { if err != nil {
errorIf(err, "Unable to fetch disk info for %#v", storageDisk) errorIf(err, "Unable to fetch disk info for %#v", storageDisk)
if err == errDiskNotFound { if isErr(err, baseErrs...) {
offlineDisks++ offlineDisks++
continue
} }
continue
} }
onlineDisks++ onlineDisks++
disksInfo[i] = info disksInfo[i] = info