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 /internal/sys/std.go | |
| 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 'internal/sys/std.go')
| -rw-r--r-- | internal/sys/std.go | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/internal/sys/std.go b/internal/sys/std.go index 828cbc45..c46bdd58 100644 --- a/internal/sys/std.go +++ b/internal/sys/std.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/fs" + "log" "os" "os/exec" "os/user" @@ -51,7 +52,14 @@ const xdgRuntimeDir = "XDG_RUNTIME_DIR" func (s *Std) Paths() hst.Paths { s.pathsOnce.Do(func() { if userid, err := GetUserID(s); err != nil { - hlog.PrintBaseError(err, "cannot obtain user id from hsu:") + // TODO(ophestra): this duplicates code in cmd/hakurei/command.go, keep this up to date until removal + if m, ok := container.GetErrorMessage(err); ok { + if m != "\x00" { + log.Print(m) + } + } else { + log.Println("cannot obtain user id from hsu:", err) + } hlog.BeforeExit() s.Exit(1) } else { @@ -61,6 +69,16 @@ func (s *Std) Paths() hst.Paths { return s.paths } +// this is a temporary placeholder until this package is removed +type wrappedError struct { + Err error + Msg string +} + +func (e *wrappedError) Error() string { return e.Err.Error() } +func (e *wrappedError) Unwrap() error { return e.Err } +func (e *wrappedError) Message() string { return e.Msg } + func (s *Std) Uid(identity int) (int, error) { s.uidOnce.Do(func() { s.uidCopy = make(map[int]struct { @@ -103,12 +121,13 @@ func (s *Std) Uid(identity int) (int, error) { if p, u.err = cmd.Output(); u.err == nil { u.uid, u.err = strconv.Atoi(string(p)) if u.err != nil { - u.err = hlog.WrapErr(u.err, "invalid uid string from hsu") + u.err = &wrappedError{u.err, "invalid uid string from hsu"} } } else if errors.As(u.err, &exitError) && exitError != nil && exitError.ExitCode() == 1 { - u.err = hlog.WrapErr(syscall.EACCES, "") // hsu prints to stderr in this case + // hsu prints an error message in this case + u.err = &wrappedError{syscall.EACCES, "\x00"} // this drops the message, handled in cmd/hakurei/command.go } else if os.IsNotExist(u.err) { - u.err = hlog.WrapErr(os.ErrNotExist, fmt.Sprintf("the setuid helper is missing: %s", hsuPath)) + u.err = &wrappedError{os.ErrNotExist, fmt.Sprintf("the setuid helper is missing: %s", hsuPath)} } return u.uid, u.err } |
