diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-30 22:49:12 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-30 22:49:12 +0900 |
| commit | f5abce9df5727904a1daa246025a87c4bfe62553 (patch) | |
| tree | 7e8c29b83e97532954dee8adb5f86962eaebca34 /system/wayland.go | |
| parent | ddb003e39b64c2417cabc291383d99b4ad64ac8f (diff) | |
system: wrap op errors
This passes more information allowing for better error handling. This eliminates generic WrapErr from system.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/wayland.go')
| -rw-r--r-- | system/wayland.go | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/system/wayland.go b/system/wayland.go index 4705acbf..f08f58b4 100644 --- a/system/wayland.go +++ b/system/wayland.go @@ -31,35 +31,31 @@ func (w *Wayland) Type() Enablement { return Process } func (w *Wayland) apply(sys *I) error { if w.sync == nil { - // this is a misuse of the API; do not return an error message + // this is a misuse of the API; do not return a wrapped error return errors.New("invalid sync") } // the Wayland op is not repeatable if *w.sync != nil { - // this is a misuse of the API; do not return an error message + // this is a misuse of the API; do not return a wrapped error return errors.New("attempted to attach multiple wayland sockets") } if err := w.conn.Attach(w.src); err != nil { - // make console output less nasty - if errors.Is(err, os.ErrNotExist) { - err = os.ErrNotExist - } - return wrapErrSuffix(err, - fmt.Sprintf("cannot attach to wayland on %q:", w.src)) + return newOpError("wayland", err, false) } else { msg.Verbosef("wayland attached on %q", w.src) } if sp, err := w.conn.Bind(w.dst, w.appID, w.instanceID); err != nil { - return wrapErrSuffix(err, - fmt.Sprintf("cannot bind to socket on %q:", w.dst)) + return newOpError("wayland", err, false) } else { *w.sync = sp msg.Verbosef("wayland listening on %q", w.dst) - return wrapErrSuffix(errors.Join(os.Chmod(w.dst, 0), acl.Update(w.dst, sys.uid, acl.Read, acl.Write, acl.Execute)), - fmt.Sprintf("cannot chmod socket on %q:", w.dst)) + if err = os.Chmod(w.dst, 0); err != nil { + return newOpError("wayland", err, false) + } + return newOpError("wayland", acl.Update(w.dst, sys.uid, acl.Read, acl.Write, acl.Execute), false) } } @@ -67,12 +63,11 @@ func (w *Wayland) revert(_ *I, ec *Criteria) error { if ec.hasType(w) { msg.Verbosef("removing wayland socket on %q", w.dst) if err := os.Remove(w.dst); err != nil && !errors.Is(err, os.ErrNotExist) { - return err + return newOpError("wayland", err, true) } msg.Verbosef("detaching from wayland on %q", w.src) - return wrapErrSuffix(w.conn.Close(), - fmt.Sprintf("cannot detach from wayland on %q:", w.src)) + return newOpError("wayland", w.conn.Close(), true) } else { msg.Verbosef("skipping wayland cleanup on %q", w.dst) return nil |
