Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error handling more uniform #99

Open
therealzoomgod opened this issue Aug 22, 2022 · 2 comments
Open

Make error handling more uniform #99

therealzoomgod opened this issue Aug 22, 2022 · 2 comments

Comments

@therealzoomgod
Copy link

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

@CourageTrain
Copy link

Hi, Can you provide a couple of code snapshots?

@therealzoomgod
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants