diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-12 06:46:12 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-12 06:52:35 +0900 |
| commit | f8760438446ee4210a479402d91018ad610bcf34 (patch) | |
| tree | ab8b3a1cbf69d2c2f42531fd786a480ca87f889e /cmd | |
| parent | 6265aea73a5f4933f4837bc1298c22fcd39b6f4f (diff) | |
internal/hlog: remove error wrapping
This was a stopgap solution that lasted for way too long. This finally removes it and prepares internal/app for some major changes.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/hakurei/command.go | 31 | ||||
| -rw-r--r-- | cmd/hakurei/print.go | 5 |
2 files changed, 27 insertions, 9 deletions
diff --git a/cmd/hakurei/command.go b/cmd/hakurei/command.go index 0ce3b71c..c3b9d85d 100644 --- a/cmd/hakurei/command.go +++ b/cmd/hakurei/command.go @@ -82,8 +82,7 @@ func buildCommand(out io.Writer) command.Command { passwdFunc = func() { var us string if uid, err := std.Uid(aid); err != nil { - hlog.PrintBaseError(err, "cannot obtain uid from setuid wrapper:") - os.Exit(1) + fatal("cannot obtain uid from setuid wrapper:", err) } else { us = strconv.Itoa(uid) } @@ -260,11 +259,33 @@ func runApp(config *hst.Config) { rs := new(app.RunState) if sa, err := a.Seal(config); err != nil { - hlog.PrintBaseError(err, "cannot seal app:") - internal.Exit(1) + hlog.BeforeExit() + fatal("cannot seal app:", err) } else { - internal.Exit(app.PrintRunStateErr(rs, sa.Run(rs))) + hlog.BeforeExit() + os.Exit(app.PrintRunStateErr(rs, sa.Run(rs))) } *(*int)(nil) = 0 // not reached } + +// fatal prints the error message according to [container.GetErrorMessage], or fallback +// prepended to err if an error message is not available, followed by a call to [os.Exit](1). +func fatal(fallback string, err error) { + m, ok := container.GetErrorMessage(err) + if !ok { + log.Fatal(fallback, err) + return + } + + // this indicates the error message has already reached stderr, outside the current process's control; + // this is only reached when hsu fails for any reason, as we do not want a second error message following hsu + // TODO(ophestra): handle the hsu error here instead of relying on a magic string + if m == "\x00" { + hlog.Verbose("*"+fallback, err) + os.Exit(1) + return + } + + log.Fatal(m) +} diff --git a/cmd/hakurei/print.go b/cmd/hakurei/print.go index 15798a20..9e1ede90 100644 --- a/cmd/hakurei/print.go +++ b/cmd/hakurei/print.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "log" - "os" "slices" "strconv" "strings" @@ -14,7 +13,6 @@ import ( "hakurei.app/hst" "hakurei.app/internal/app/state" - "hakurei.app/internal/hlog" "hakurei.app/system/dbus" ) @@ -26,8 +24,7 @@ func printShowSystem(output io.Writer, short, flagJSON bool) { // get hid by querying uid of identity 0 if uid, err := std.Uid(0); err != nil { - hlog.PrintBaseError(err, "cannot obtain uid from setuid wrapper:") - os.Exit(1) + fatal("cannot obtain uid from setuid wrapper:", err) } else { info.User = (uid / 10000) - 100 } |
