forked from security/hakurei
hst: replace internal/app error
This turns out to still be quite useful across internal/app and its relatives. Perhaps a cleaner replacement for baseError. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
30
hst/hst.go
30
hst/hst.go
@@ -2,12 +2,42 @@
|
||||
package hst
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/container/seccomp"
|
||||
"hakurei.app/system"
|
||||
"hakurei.app/system/dbus"
|
||||
)
|
||||
|
||||
// An AppError is returned while starting an app according to [hst.Config].
|
||||
type AppError struct {
|
||||
Step string
|
||||
Err error
|
||||
Msg string
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string { return e.Err.Error() }
|
||||
func (e *AppError) Unwrap() error { return e.Err }
|
||||
func (e *AppError) Message() string {
|
||||
if e.Msg != "" {
|
||||
return e.Msg
|
||||
}
|
||||
|
||||
switch {
|
||||
case errors.As(e.Err, new(*os.PathError)),
|
||||
errors.As(e.Err, new(*os.LinkError)),
|
||||
errors.As(e.Err, new(*os.SyscallError)),
|
||||
errors.As(e.Err, new(*net.OpError)):
|
||||
return "cannot " + e.Error()
|
||||
|
||||
default:
|
||||
return "cannot " + e.Step + ": " + e.Error()
|
||||
}
|
||||
}
|
||||
|
||||
// Paths contains environment-dependent paths used by hakurei.
|
||||
type Paths struct {
|
||||
// temporary directory returned by [os.TempDir] (usually `/tmp`)
|
||||
|
||||
Reference in New Issue
Block a user