summaryrefslogtreecommitdiffhomepage
path: root/pkg/syserr
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-05-12 00:27:13 +0000
committergVisor bot <gvisor-bot@google.com>2021-05-12 00:27:13 +0000
commitccc377e3a485ddda506be9ff0149bb936f954816 (patch)
treeeaaa3cefdce0b7680fa9bf575ba34f17a51948e4 /pkg/syserr
parent4c1436afe028fe0c45f51e1dfe9e7cd493eb8fb9 (diff)
parent49eb3da98aeb436011ec9d895727b237ec2ea93f (diff)
Merge release-20210503.0-36-g49eb3da98 (automated)
Diffstat (limited to 'pkg/syserr')
-rw-r--r--pkg/syserr/netstack.go2
-rw-r--r--pkg/syserr/syserr.go25
2 files changed, 11 insertions, 16 deletions
diff --git a/pkg/syserr/netstack.go b/pkg/syserr/netstack.go
index 79e564de6..90be24e15 100644
--- a/pkg/syserr/netstack.go
+++ b/pkg/syserr/netstack.go
@@ -38,7 +38,7 @@ var (
ErrPortInUse = New((&tcpip.ErrPortInUse{}).String(), linux.EADDRINUSE)
ErrBadLocalAddress = New((&tcpip.ErrBadLocalAddress{}).String(), linux.EADDRNOTAVAIL)
ErrClosedForSend = New((&tcpip.ErrClosedForSend{}).String(), linux.EPIPE)
- ErrClosedForReceive = New((&tcpip.ErrClosedForReceive{}).String(), nil)
+ ErrClosedForReceive = New((&tcpip.ErrClosedForReceive{}).String(), linux.NOERRNO)
ErrTimeout = New((&tcpip.ErrTimeout{}).String(), linux.ETIMEDOUT)
ErrAborted = New((&tcpip.ErrAborted{}).String(), linux.EPIPE)
ErrConnectStarted = New((&tcpip.ErrConnectStarted{}).String(), linux.EINPROGRESS)
diff --git a/pkg/syserr/syserr.go b/pkg/syserr/syserr.go
index b5881ea3c..d70521f32 100644
--- a/pkg/syserr/syserr.go
+++ b/pkg/syserr/syserr.go
@@ -34,24 +34,19 @@ type Error struct {
// linux.Errno.
noTranslation bool
- // errno is the linux.Errno this Error should be translated to. nil means
- // that this Error should be translated to a nil linux.Errno.
- errno *linux.Errno
+ // errno is the linux.Errno this Error should be translated to.
+ errno linux.Errno
}
// New creates a new Error and adds a translation for it.
//
// New must only be called at init.
-func New(message string, linuxTranslation *linux.Errno) *Error {
+func New(message string, linuxTranslation linux.Errno) *Error {
err := &Error{message: message, errno: linuxTranslation}
- if linuxTranslation == nil {
- return err
- }
-
// TODO(b/34162363): Remove this.
- errno := linuxTranslation.Number()
- if errno <= 0 || errno >= len(linuxBackwardsTranslations) {
+ errno := linuxTranslation
+ if errno < 0 || int(errno) >= len(linuxBackwardsTranslations) {
panic(fmt.Sprint("invalid errno: ", errno))
}
@@ -74,7 +69,7 @@ func New(message string, linuxTranslation *linux.Errno) *Error {
// NewDynamic should only be used sparingly and not be used for static error
// messages. Errors with static error messages should be declared with New as
// global variables.
-func NewDynamic(message string, linuxTranslation *linux.Errno) *Error {
+func NewDynamic(message string, linuxTranslation linux.Errno) *Error {
return &Error{message: message, errno: linuxTranslation}
}
@@ -87,7 +82,7 @@ func NewWithoutTranslation(message string) *Error {
return &Error{message: message, noTranslation: true}
}
-func newWithHost(message string, linuxTranslation *linux.Errno, hostErrno unix.Errno) *Error {
+func newWithHost(message string, linuxTranslation linux.Errno, hostErrno unix.Errno) *Error {
e := New(message, linuxTranslation)
addLinuxHostTranslation(hostErrno, e)
return e
@@ -119,10 +114,10 @@ func (e *Error) ToError() error {
if e.noTranslation {
panic(fmt.Sprintf("error %q does not support translation", e.message))
}
- if e.errno == nil {
+ errno := int(e.errno)
+ if errno == linux.NOERRNO {
return nil
}
- errno := e.errno.Number()
if errno <= 0 || errno >= len(linuxBackwardsTranslations) || !linuxBackwardsTranslations[errno].ok {
panic(fmt.Sprintf("unknown error %q (%d)", e.message, errno))
}
@@ -131,7 +126,7 @@ func (e *Error) ToError() error {
// ToLinux converts the Error to a Linux ABI error that can be returned to the
// application.
-func (e *Error) ToLinux() *linux.Errno {
+func (e *Error) ToLinux() linux.Errno {
if e.noTranslation {
panic(fmt.Sprintf("No Linux ABI translation available for %q", e.message))
}