zeromq / pyzmq

PyZMQ: Python bindings for zeromq
http://zguide.zeromq.org/py:all
BSD 3-Clause "New" or "Revised" License
3.73k stars 636 forks source link

When raising ZMQError: Permission denied it would be helpful if context were given #1287

Open bowlofeggs opened 5 years ago

bowlofeggs commented 5 years ago

Greetings!

I recently received this traceback:

Traceback (most recent call last):                                                                  
  File "/usr/lib/python3.7/site-packages/moksha/hub/hub.py", line 455, in __init_producers 
    producer_obj = producer_class(self)                                                             
  File "/usr/lib/python3.7/site-packages/moksha/hub/monitoring.py", line 47, in __init__            
    self.socket.bind(endpoint)    
  File "zmq/backend/cython/socket.pyx", line 547, in zmq.backend.cython.socket.Socket.bind 
  File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc._check_rc 
zmq.error.ZMQError: Permission denied

It turned out that it was unable to create /var/run/fedmsg/monitoring-fedmsg-hub.socket, but it would have made debugging easier for me if it had told me that along with the ZMQError.

Could we make it so that the error includes info about what it was getting permission denied on? Something like this would have been helpful:

zmq.error.ZMQError: Permission denied: Unable to bind to /var/run/fedmsg/monitoring-fedmsg-hub.socket

Thanks!

minrk commented 5 years ago

That would indeed be great! It might be difficult, though, because we don't have path information in the underlying error. All we have is that it was EPERM.

To do this, I think we'd need to special-case error handing in bind/connect and re-raise a new error:

# pseudo-ish code
try:
   ...
except ZMError as e:
    if EPERM and url.startswith('ipc://'):
        raise ZMQError(EPERM, message=message_with_url)
minrk commented 5 years ago

1301 does this with ENOENT, EPERM could be added as well.