diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-09 22:04:35 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-09 22:04:35 +0900 |
| commit | a941ac025f9f3a942cab04a6f2447e4cab0e616c (patch) | |
| tree | a309e19a16505b27457e0e1d1bac2d28d0a99105 /container/errors.go | |
| parent | 87b5c30ef6d5b7b8a10d6a5a8610054c403923e6 (diff) | |
container/init: unwrap descriptive fatal error
These errors are printed with a descriptive message prefixed to them, so it is more readable to expose the underlying errno.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/errors.go')
| -rw-r--r-- | container/errors.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/container/errors.go b/container/errors.go index e3f4b9d9..884c8a04 100644 --- a/container/errors.go +++ b/container/errors.go @@ -59,6 +59,7 @@ func messagePrefixP[V any, T interface { return zeroString, false } +// MountError wraps errors returned by syscall.Mount. type MountError struct { Source, Target, Fstype string @@ -74,6 +75,7 @@ func (e *MountError) Unwrap() error { return e.Errno } +func (e *MountError) Message() string { return "cannot " + e.Error() } func (e *MountError) Error() string { if e.Flags&syscall.MS_BIND != 0 { if e.Flags&syscall.MS_REMOUNT != 0 { @@ -90,6 +92,15 @@ func (e *MountError) Error() string { return "mount " + e.Target + ": " + e.Errno.Error() } +// optionalErrorUnwrap calls [errors.Unwrap] and returns the resulting value +// if it is not nil, or the original value if it is. +func optionalErrorUnwrap(err error) error { + if underlyingErr := errors.Unwrap(err); underlyingErr != nil { + return underlyingErr + } + return err +} + // errnoFallback returns the concrete errno from an error, or a [os.PathError] fallback. func errnoFallback(op, path string, err error) (syscall.Errno, *os.PathError) { var errno syscall.Errno |
