Swind / pure-python-adb

This is pure-python implementation of the ADB client.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make error handling more uniform

therealzoomgod opened this issue · 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

Hi, Can you provide a couple of code snapshots?

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