From 8690419c2d577a27efe3cfcafc39c05b7646926b Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 15 Sep 2025 01:44:43 +0900 Subject: 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 --- hst/hst.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'hst/hst.go') diff --git a/hst/hst.go b/hst/hst.go index d9c1168b..c9a23d7a 100644 --- a/hst/hst.go +++ b/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`) -- cgit v1.3.1