Skip to content

Commit

Permalink
Replace common exceptions thrown on debug session start with readable…
Browse files Browse the repository at this point in the history
… messages.
  • Loading branch information
martomo committed Feb 4, 2018
1 parent 4fe59cf commit 1510f06
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions xdebug/protocol.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import re
import socket
import sys
Expand Down Expand Up @@ -250,6 +251,16 @@ def listen(self):
self.socket = None
except:
e = sys.exc_info()[1]
debug('Failed to create socket: %s' % e)
# Substitute exception with readable (custom) message
if hasattr(e, 'errno'):
address_or_port = 'address (%s:%d)' % (self.host, self.port) if self.host is not '' else 'port (%d)' % self.port
if e.errno == errno.EADDRINUSE:
e = 'Another application is already listening on configured %s.' % address_or_port
elif e.errno == errno.EADDRNOTAVAIL:
e = 'Configured %s is not accessible.' % address_or_port
elif e.errno == errno.ENOEXEC and self.host is not '':
e = 'Hostname (%s) is not specified in hosts file or is an IPv6 address.' % self.host
raise ProtocolListenException(e)

# Accept incoming connection on configured port
Expand Down

0 comments on commit 1510f06

Please sign in to comment.