Documentation ¶
Overview ¶
Package punix examines unix.Errno errors and identifies Unix-like platforms.
Index ¶
- func Errno(err error) (errnoValue unix.Errno)
- func ErrnoError(err error, includeError ...bool) (errnoString string)
- func ErrnoString(label string, err error) (errnoNumericString string)
- func IsConnectionRefused(err error) (isConnectionRefused bool)
- func IsENOENT(err error) (isENOENT bool)
- func OsVersion() (version string, hasVersion bool, err error)
- func Processor() (model string, err error)
- func SignalString(signal os.Signal) (s string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errno ¶
Errno scans an error chain for a unix.Errno type.
- if no errno value exists, unix.Errno 0x0 is returned
- unlike most error implementations, unix.Errno type is uintptr
- to check for error condition of a unix.Errno error: if errno != 0 {…
- to obtain errno number: int(errno)
- to print errno number: fmt.Sprintf("%d", errno) → "1"
- to print errno message: fmt.Sprintf("%v", unix.EPERM) → "operation not permitted"
- to obtain errno name: unix.ErrnoName(unix.EPERM) → "EPERM"
- to print hexadecimal errno:
Note: unix.Errno.Error has value receiver. Errno checks:
Errno(nil) == 0 → true. if errno != 0 {… int(errno) // numeric value if errno == unix.ENOENT… fmt.Sprintf("%d", unix.EPERM) → "1" fmt.Printf("%v", errno) → "state not recoverable" unix.ErrnoName(unix.EPERM) → "EPERM" var i, s = int(errno), "" if i < 0 { i = -i; s = "-" } fmt.Printf("%s0x%x", s, i) → 0x68
func ErrnoError ¶
ErrnoError gets the errno interpretation if the error chain does contain a unix.Errno type. if includeError is true, the error chain’s error message is prepended. if includeError is true and err is nil "OK" is returned if includeError is false or missing and no errno exists, the empty string is returned
func ErrnoString ¶ added in v0.4.86
ErrnoString returns the errno number as a string if the err error chain has a non-zero syscall.Errno error.
- if label is empty string, no label is returned
- if no syscall.Errno is found or it is zero, the empty string is returned
- ErrnoString("errno", nil) → ""
- ErrnoString("errno", unix.EPERM) → "errno: EPERM 1 0x1"
- ErrnoString("errno", unix.Errno(math.MaxUint)) → "-1 -0x1"
func IsConnectionRefused ¶
IsConnectionRefused searches the error chsin of err for unix.ECONNREFUSED net.Dialer errors for closed socket
func IsENOENT ¶
IsENOENT returns true if the root cause of err is file not found. Can be used with os.Open* file not found
func Processor ¶ added in v0.4.74
Processor returns human readable string like "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz"
func SignalString ¶ added in v0.4.179
“signal “segmentation fault” SIGSEGV 11 0xb”
- os.Signal is a signal type available on all platforms: interface { String() string; Signal() }
- a signal is an operating-system dependent small non-zero positive integer
- not all operating systems, eg. Windows, Android, or iOS, have signals
- os.Signal is implemented on most platforms by unix.Signal of underlying type int
- values of unix.Signal are platform-dependent constants, eg. unix.SIGINT
- a signal has a name, a single upper case word like “SIGINT”
- unix.SignalName returns the name of any valid unix.Signal value. Invalid signals returns their integer number “-1”
- a signal has a description, a short lower-case sentence like “segmentation fault”
- unix.Signal.String or os.Signal.String returns the description for a signal value. Invalid signals returns a numeric value “signal -1”
- the lowest signal value for all known platforms is 1 SIGHUP
- it is not possible to retrieve the number of the last signal for a platform. Typically, the highest value is 31 SIGUSR2, less than 100, and there are no intermediate ununsed numbers
- unix.Signal is as of go1.22.3 not defined for operating systems: android illumos ios js plan9 wasip1 windows
Types ¶
This section is empty.