| 1 | // Copyright 2021 The gVisor Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Package errors holds the standardized error definition for gVisor. |
| 16 | package errors |
| 17 | |
| 18 | import ( |
| 19 | "inet.af/netstack/abi/linux/errno" |
| 20 | ) |
| 21 | |
| 22 | // Error represents a syscall errno with a descriptive message. |
| 23 | type Error struct { |
| 24 | errno errno.Errno |
| 25 | message string |
| 26 | } |
| 27 | |
| 28 | // New creates a new *Error. |
| 29 | func New(err errno.Errno, message string) *Error { |
| 30 | return &Error{ |
| 31 | errno: err, |
| 32 | message: message, |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // Error implements error.Error. |
| 37 | func (e *Error) Error() string { return e.message } |
| 38 | |
| 39 | // Errno returns the underlying errno.Errno value. |
| 40 | func (e *Error) Errno() errno.Errno { return e.errno } |