What's the most idiomatic way to check error messages? My use case is that in err := os.Remove(path)
, I consider a success either:
A) if err == nil
or
B) if err != nil
but the error is thrown because the file was not found.
any other error should cause the removal to retry. Currently I've wrapped this in a for { ... }
loop and am checking:
if err == nil || strings.Contains(err.Error(), "no such file") {
// Success
} else {
// Fail
}
Since the docs say:
If there is an error, it will be of type *PathError.
I don't think there's a way to check by type assertion. Am I missing something fundamental? My error handling in Go has always felt somewhat slapdash.