pure-python-adb icon indicating copy to clipboard operation
pure-python-adb copied to clipboard

Make error handling more uniform

Open therealzoomgod opened this issue 2 years ago • 2 comments

When a RunTimeError is raised (Example: ADB server not available) you just get a text string in e.arg

When a ConnectionResetError is raised e.arg[0] has the error code as an int plus you can get a text string message.

The second approach makes writing error handlers much cleaner and easier compared to parsing strings.

Thanks

therealzoomgod avatar Aug 22 '22 13:08 therealzoomgod

Hi, Can you provide a couple of code snapshots?

CourageTrain avatar Aug 31 '22 04:08 CourageTrain

I'm just suggesting some custom exception classes as opposed to raising a generic RuntimeError.

This is how I currently am parsing the errors

def _parseError(e):

if type(e.args) is type(()) and len(e.args) >= 2:
    if type(e.args[0]) is type(1):
        return e.args[0], e.args[1]

msg = '%s' % e
err = 0

a = msg.find('[WinError')
if a > -1:
    b = msg.find(']', a)
    err = int(msg[a+10:b])
elif msg.find('127.0.0.1:') > -1:
  a = msg.find('127.0.0.1:')
  if a > -1:
    msg = msg[a:a+15]
    err = eErrors.ADB_CLIENT_LEFT
else:
    err = eErrors.ADB_CLIENT_UNKNOWN

if err == eErrors.ADB_SERVER_UNAVAILABLE:
    msg = 'ADB server not found'

return err, msg

therealzoomgod avatar Sep 01 '22 21:09 therealzoomgod