pywayland icon indicating copy to clipboard operation
pywayland copied to clipboard

Proposal: Remove exceptions from Display.add_socket()

Open heuer opened this issue 2 years ago • 1 comments

Im my opinion it would nice if the method does not raise any exception but return None in case of an error. This would largely correspond to the C implementation, which returns -1 in case of error and 0 in case of success. In my suggestion -1 would be None and 0 would be the name of the socket. In my opinion, the compositor should be responsible for responding to an error, not pywayland.

See also https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/486 why it might make sense to try multiple socket names.

If the method does not raise any errors, the following implementation would be possible without catching a generic Exception:

for i in range(1, 33):
    if display.add_socket(f'wayland-{i}'):
        break

heuer avatar Feb 27 '24 19:02 heuer

Currently the above should require the following code:

for i in range(1, 33):
    try:
        display.add_socket(f'wayland-{i}')
    except (RuntimeError, Exception):
        continue  # Maybe socket in use
    break

heuer avatar Mar 06 '24 23:03 heuer