system/wayland: improve error descriptions
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 1m52s
Test / Hpkg (push) Successful in 3m42s
Test / Sandbox (race detector) (push) Successful in 3m57s
Test / Hakurei (race detector) (push) Successful in 5m17s
Test / Hakurei (push) Successful in 2m18s
Test / Flake checks (push) Successful in 1m35s

A lot of these errors have very short and nondescript descriptions. These are only returned on incorrect API usage, but it makes sense to make them more descriptive anyway.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-08-30 16:51:40 +09:00
parent 0122593312
commit b12c290f12
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q

View File

@ -10,6 +10,7 @@ import (
"syscall" "syscall"
) )
// Conn represents a connection to the wayland display server.
type Conn struct { type Conn struct {
conn *net.UnixConn conn *net.UnixConn
@ -25,7 +26,7 @@ func (c *Conn) Attach(p string) (err error) {
defer c.mu.Unlock() defer c.mu.Unlock()
if c.conn != nil { if c.conn != nil {
return errors.New("attached") return errors.New("socket already attached")
} }
c.conn, err = net.DialUnix("unix", nil, &net.UnixAddr{Name: p, Net: "unix"}) c.conn, err = net.DialUnix("unix", nil, &net.UnixAddr{Name: p, Net: "unix"})
@ -51,15 +52,16 @@ func (c *Conn) Close() error {
return nil return nil
} }
func (c *Conn) Bind(p, appID, instanceID string) (*os.File, error) { // Bind binds the new socket to pathname.
func (c *Conn) Bind(pathname, appID, instanceID string) (*os.File, error) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
if c.conn == nil { if c.conn == nil {
return nil, errors.New("not attached") return nil, errors.New("socket not attached")
} }
if c.done != nil { if c.done != nil {
return nil, errors.New("bound") return nil, errors.New("socket already bound")
} }
if rc, err := c.conn.SyscallConn(); err != nil { if rc, err := c.conn.SyscallConn(); err != nil {
@ -67,7 +69,7 @@ func (c *Conn) Bind(p, appID, instanceID string) (*os.File, error) {
return nil, err return nil, err
} else { } else {
c.done = make(chan struct{}) c.done = make(chan struct{})
return bindRawConn(c.done, rc, p, appID, instanceID) return bindRawConn(c.done, rc, pathname, appID, instanceID)
} }
} }