diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-15 01:44:43 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-15 01:44:43 +0900 |
| commit | 8690419c2d577a27efe3cfcafc39c05b7646926b (patch) | |
| tree | c792c397d9026c01cecb3a7610d9ad9f7149f1fe /hst/hst.go | |
| parent | 1cdc6b4246ac82adb0c9ed7620d3f7225f1a3e7f (diff) | |
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>
Diffstat (limited to 'hst/hst.go')
| -rw-r--r-- | hst/hst.go | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -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`) |
