add not found error for ipset set and entry delete

This commit is contained in:
m1093782566
2017-12-18 17:22:26 +08:00
parent 65a7ecf147
commit e6b9b5e0c3
3 changed files with 23 additions and 2 deletions

View File

@@ -322,4 +322,20 @@ func validatePortRange(portRange string) bool {
return true
}
// IsNotFoundError returns true if the error indicates "not found". It parses
// the error string looking for known values, which is imperfect but works in
// practice.
func IsNotFoundError(err error) bool {
es := err.Error()
if strings.Contains(es, "does not exist") {
// set with the same name already exists
return true
}
if strings.Contains(es, "element is missing") {
// entry is missing from the set
return true
}
return false
}
var _ = Interface(&runner{})