kevinabrandon / AboveTustin

ADS-B Twitter Bot. Uses dump1090-mutability to track airplanes and then tweets whenever an airplane flies overhead.
MIT License
72 stars 21 forks source link

Exception handling changes #22

Closed wiseman closed 6 years ago

wiseman commented 6 years ago

Be more discerning in the exceptions that are caught, and show more info about exceptions when they happen.

The first issue is a bare except: will even catch the KeyboardInterrupt exception generated by ctrl-c, so sometimes you would have to press ctrl-c twice to stop the program. Now we except Exception:.

The second issue is that not much info was shown about an exception, which especially during development could make debugging difficult. Previously:

exception in loadmap()
<class 'selenium.common.exceptions.TimeoutException'>

With this change:

exception in Tweet():
Traceback (most recent call last):
  File "tracker.py", line 227, in <module>
    Tweet(a[0], havescreenshot)
  File "tracker.py", line 90, in Tweet
    tweet = Template(parser.get('tweet', 'tweet_template')).substitute(templateArgs)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/string.py", line 126, in substitute
    return self.pattern.sub(convert, self.template)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/string.py", line 119, in convert
    return str(mapping[named])
KeyError: 'dist'
kevinabrandon commented 6 years ago

Thanks for that