#383: Depcheck and Upgradepath crash if yourls is not configured ----------------------+----------------------------------------------------- Reporter: tflink | Owner: tflink Type: defect | Status: assigned Priority: critical | Milestone: 0.7.0 Component: core | Resolution: Keywords: | ----------------------+----------------------------------------------------- Comment (by kparal):
I still receive a traceback when I fill in everything in yourls.conf except username.
{{{
12:00:55 ERROR| Traceback (most recent call last): 12:00:55 ERROR| File "/usr/lib/python2.7/site- packages/autoqa/decorators.py", line 72, in newf 12:00:55 ERROR| f_result = f(*args, **kwargs) #call the decorated function 12:00:55 ERROR| File "/usr/share/autotest/client/site_tests/rpmlint/rpmlint.py", line 85, in run_once 12:00:55 ERROR| self.post_results(optin={'pkg': name, 'kojitag': kojitag}) 12:00:55 ERROR| File "/usr/lib/python2.7/site-packages/autoqa/test.py", line 232, in post_results 12:00:55 ERROR| self._send_email(test_detail, optin=optin, logname=logname) 12:00:55 ERROR| File "/usr/lib/python2.7/site-packages/autoqa/test.py", line 293, in _send_email 12:00:55 ERROR| logname=logname) 12:00:55 ERROR| File "/usr/lib/python2.7/site-packages/autoqa/test.py", line 335, in _create_email_body 12:00:55 ERROR| url = self._shorten_url(self.url['result_dir'] + urllib.quote(logname), test_detail) 12:00:55 ERROR| File "/usr/lib/python2.7/site-packages/autoqa/test.py", line 180, in _shorten_url 12:00:55 ERROR| url = self._yourls_client.shorten(url) 12:00:55 ERROR| File "/usr/lib/python2.7/site- packages/yourls/client.py", line 109, in shorten 12:00:55 ERROR| if raw_data['status'] == 'fail': 12:00:55 ERROR| KeyError: 'status' }}}
Tim, please make following changes in yourls/client.py: * Test all arguments in __init__() for emptiness, not for None. Use "if not username" instead of "if username is None". The same for password, apiurl, etc. * Don't use sys.exit(), throw an exception instead. * Define a base exception YourlsError(StandardError) and inherit all other exceptions from it. We can then catch just this base exception if needed. * Make sure raw_data in shorten() contains required keys before accessing it, or guard the whole block with some YourlsError descendant exception.
After new release of python-yourls is released, we will adjust _get_yourls_client() and _shorten_url() in test.py to catch YourlsError exceptions and our test won't crash if something in python-yourls goes wrong.