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

parse ptp errors gracefully #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

meelash
Copy link

@meelash meelash commented Mar 16, 2018

First, chdkptp errors do not have a 'message' key, instead, it is 'msg'.
Then, for some reason the dictionary get() method throws an error:

TypeError: 'NoneType' object is not callable

no matter if the key exists, or not. Not sure why that is so.

For example, using str(parse_table(err_table)), the structure of err_table is as follows:

{'msg': 'I/O error', 'etype': 'ptp', 'traceback': '\nstack traceback:\n\t[C]: in function 'chdk_connection.execlua'\n\t[C]: in function 'pcall'\n\t...on2.7/site-packages/chdkptp/vendor/chdkptp/lua/chdku.lua:2084: in function 'execlua_pcall'\n\t...on2.7/site-packages/chdkptp/vendor/chdkptp/lua/chdku.lua:1016: in function <...on2.7/site-packages/chdkptp/vendor/chdkptp/lua/chdku.lua:966>\n\t(...tail calls...)\n\t[string ""]:4: in function <[string ""]:1>\n\t[C]: in function 'pcall'\n\t[string ""]:1: in main chunk', 'ptp_rc': 767}

then the following error is thrown when using get() (no matter which key, just for example here is ptp_rc):

File "/Users/blah/Books/software/pi-scan/env/lib/python2.7/site-packages/chdkptp/lua.py", line 15, in init
errcode = err_table.get('ptp_rc')
TypeError: 'NoneType' object is not callable

but using err_table['ptp_rc'], it will correctly get that key.

Not sure why that happens, but the simple fix is to use brackets. Yes it will throw if the key doesn't exists, but currently it is throwing in all cases, so at the very least, it is better than the current situation ;)

meelash and others added 2 commits March 16, 2018 23:36
First, chdkptp errors do not have a 'message' key, instead, it is 'msg'.
Then, for some reason the dictionary get() method throws an error:
TypeError: 'NoneType' object is not callable
no matter if the key exists, or not. Not sure why that is so.
…aries nicely. Since they have special properties like the PTP traceback.
@meelash
Copy link
Author

meelash commented Mar 20, 2018

The second commit is to expose the PTPError class so client libraries can catch it and parse it correctly, for example, by doing something with the PTP traceback property it has.

@R-ay R-ay mentioned this pull request Sep 26, 2019
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

Successfully merging this pull request may close these issues.

1 participant