summaryrefslogtreecommitdiffhomepage
path: root/pkg/syserror/syserror.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2021-03-18 12:14:01 -0700
committergVisor bot <gvisor-bot@google.com>2021-03-18 12:19:57 -0700
commit7fac7e32f3a866134bcee499dfc64459946dfe9d (patch)
treec678f8e392949072c55d26398e2a5b1b5449c67d /pkg/syserror/syserror.go
parent29be908ab69d2d333572f6990d331e494b1e51fd (diff)
Translate syserror when validating partial IO errors
syserror allows packages to register translators for errors. These translators should be called prior to checking if the error is valid, otherwise it may not account for possible errors that can be returned from different packages, e.g. safecopy.BusError => syserror.EFAULT. Second attempt, it passes tests now :-) PiperOrigin-RevId: 363714508
Diffstat (limited to 'pkg/syserror/syserror.go')
-rw-r--r--pkg/syserror/syserror.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/pkg/syserror/syserror.go b/pkg/syserror/syserror.go
index 97de17afe..56b621357 100644
--- a/pkg/syserror/syserror.go
+++ b/pkg/syserror/syserror.go
@@ -130,17 +130,15 @@ func AddErrorUnwrapper(unwrap func(e error) (unix.Errno, bool)) {
// TranslateError translates errors to errnos, it will return false if
// the error was not registered.
func TranslateError(from error) (unix.Errno, bool) {
- err, ok := errorMap[from]
- if ok {
- return err, ok
+ if err, ok := errorMap[from]; ok {
+ return err, true
}
// Try to unwrap the error if we couldn't match an error
// exactly. This might mean that a package has its own
// error type.
for _, unwrap := range errorUnwrappers {
- err, ok := unwrap(from)
- if ok {
- return err, ok
+ if err, ok := unwrap(from); ok {
+ return err, true
}
}
return 0, false