[Bug 280034] New: osc buildinfo has bad error handling
https://bugzilla.novell.com/show_bug.cgi?id=280034 Summary: osc buildinfo has bad error handling Product: openSUSE.org Version: unspecified Platform: Other OS/Version: Other Status: NEW Severity: Normal Priority: P5 - None Component: BuildService AssignedTo: bnc-team-screening@forge.provo.novell.com ReportedBy: suse-beta@cboltz.de QAContact: adrian@novell.com osc buildinfo has bad error handling. Examples are a) running "osc buildinfo" in a directory that does *not* contain a .osc directory osc buildinfo openSUSE_10.2 x86_64 Traceback (most recent call last): File "/usr/bin/osc", line 10, in <module> sys.exit( osc.main() ) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 240, in main return self.cmd(args) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 263, in cmd retval = self.onecmd(argv) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 379, in onecmd return self._dispatch_cmd(handler, argv) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 1109, in _dispatch_cmd return handler(argv[0], opts, *args) File "/usr/lib/python2.5/site-packages/osc/commandline.py", line 968, in do_buildinfo package = store_read_package(wd) File "/usr/lib/python2.5/site-packages/osc/core.py", line 1348, in store_read_package p = open(os.path.join(dir, store, '_package')).readlines()[0].strip() IOError: [Errno 2] No such file or directory: './.osc/_package' b) in case of a "404" error (already reported in another bug) there's also a lengthly message with a backtrace (sorry, I don't have it available right now) Please add some error handling ;-) -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
https://bugzilla.novell.com/show_bug.cgi?id=280034 mhorvath@novell.com changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|bnc-team- |poeml@novell.com |screening@forge.provo.novell| |.com | -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
https://bugzilla.novell.com/show_bug.cgi?id=280034 ------- Comment #1 from suse-beta@cboltz.de 2007-06-02 14:25 MST ------- case b) (404 error) is reproducable by specifying an invalid target ;-) # osc buildinfo openSUSE_10.2 nixmitarch Traceback (most recent call last): File "/usr/bin/osc", line 10, in <module> sys.exit( osc.main() ) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 240, in main return self.cmd(args) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 263, in cmd retval = self.onecmd(argv) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 379, in onecmd return self._dispatch_cmd(handler, argv) File "/usr/lib/python2.5/site-packages/osc/cmdln.py", line 1109, in _dispatch_cmd return handler(argv[0], opts, *args) File "/usr/lib/python2.5/site-packages/osc/commandline.py", line 992, in do_buildinfo print ''.join(get_buildinfo(apiurl, project, package, platform, arch, specfile=spec)) File "/usr/lib/python2.5/site-packages/osc/core.py", line 1285, in get_buildinfo f = http_GET(u) File "/usr/lib/python2.5/site-packages/osc/core.py", line 682, in http_GET def http_GET(*args, **kwargs): return http_request('GET', *args, **kwargs) File "/usr/lib/python2.5/site-packages/osc/core.py", line 673, in http_request fd = urllib2.urlopen(req, data=data) File "/usr/lib/python2.5/urllib2.py", line 121, in urlopen return _opener.open(url, data) File "/usr/lib/python2.5/urllib2.py", line 380, in open response = meth(req, response) File "/usr/lib/python2.5/urllib2.py", line 491, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.5/urllib2.py", line 412, in error result = self._call_chain(*args) File "/usr/lib/python2.5/urllib2.py", line 353, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 817, in http_error_401 url, req, headers) File "/usr/lib/python2.5/urllib2.py", line 795, in http_error_auth_reqed return self.retry_http_basic_auth(host, req, realm) File "/usr/lib/python2.5/urllib2.py", line 805, in retry_http_basic_auth return self.parent.open(req) File "/usr/lib/python2.5/urllib2.py", line 380, in open response = meth(req, response) File "/usr/lib/python2.5/urllib2.py", line 491, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.5/urllib2.py", line 418, in error return self._call_chain(*args) File "/usr/lib/python2.5/urllib2.py", line 353, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 499, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
https://bugzilla.novell.com/show_bug.cgi?id=280034 poeml@novell.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
https://bugzilla.novell.com/show_bug.cgi?id=280034#c2 Peter Poeml <poeml@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |suse-tux@gmx.de --- Comment #2 from Peter Poeml <poeml@novell.com> 2007-07-13 06:27:42 MST --- a) was recently fixed by Marcus. b) hard to fix in a breeze. I would like to solve that generically. The thing is, I would like to avoid adding handling for 404s, 500s, and so on in a thousand places. Rather, I would like to handle them centrally in one place (the http_request() function). However, there are places where a 404 is expected and are not considered an error condition, and osc is not supposed to quit then. I don't know yet which is the easiest way to implement this cleanly, but it needs a clean solution anyway. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034#c3 --- Comment #3 from Christian Boltz <suse-beta@cboltz.de> 2007-07-13 16:45:32 MST --- Just an idea, without knowing the code: add a parameter to http_request() that lists the allowed (additional?) status-codes. This parameter should be optional so that you don't need to specify "200, nothing else" all the time ;-) -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034#c4 --- Comment #4 from Marcus Hüwe <suse-tux@gmx.de> 2007-07-25 05:08:31 MST --- I thought about it a bit.. what about something like this: def http_safe_request(func, *args): try: return func(*args) except urllib2.HTTPError, e: if e.code == 404: print >>sys.stderr, 'error 404 - does not exist' sys.exit(1) elif e.code == 403: print >>sys.stderr, 'error 403 - access denied' sys.exit(1) elif e.code == 401: print >>sys.stderr, 'error 401 - authentication required' sys.exit(1) else: print >>sys.stderr, 'unexpected error: \'%s\'' % e.code sys.exit(1) And everytime we need exception handling (like osc buildinfo) we could call http_safe_request(http_POST, url, otherdata) (in the case of osc buildinfo) and if urllib2 throws and exception it'll be handled immediately. The advantage of such a function is that we don't have to do exception handling in every method which uses a http_* call (this would blow up the code IMHO). -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034#c5 --- Comment #5 from Marcus Hüwe <suse-tux@gmx.de> 2007-10-27 12:16:07 MST --- Today I wrote a more extended version of this exception handling. With this new version all urllib2.HTTPError exceptions will be catched in the http_request() method (thanks to darix for hinting me to this method and his remarks:) ) unless a parameter is added to the http_GET, http_PUT... calls which forces the http_request() method to re-raise the exception so that it can be handled in calling method (this is needed in some cases). If you now run "osc dosth <non-existing>" it will print a generic error message for 404-errors (if you need a more precise error message you can easily overwrite the standard message - so it's still flexible IMHO). I attached a small diff (with the current implementation osc will probably often raise an "AttributeError" exception which can be ignored atm). usage: # all urllib2.HTTPError exceptions will be catched: f = http_GET(u) # no exceptions will be catched (so this line should by nested in a try-except block): f = http_GET(u, hasHandler=True) # if a 404 exception is raised it'll print 'user does not exist' instead of 'no such file or package or project' (standard message) hdl = HTTPError_Handler('404', 'user does not exist', None) f = http_GET(u, hasHandler=False, customHandlers={ '404' : hdl }) -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034#c6 --- Comment #6 from Marcus Hüwe <suse-tux@gmx.de> 2007-10-27 12:17:32 MST --- Created an attachment (id=180918) --> (https://bugzilla.novell.com/attachment.cgi?id=180918) enables exception handling in the http_request() method -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034 User suse-tux@gmx.de added comment https://bugzilla.novell.com/show_bug.cgi?id=280034#c7 Marcus Hüwe <suse-tux@gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dkukawka@novell.com --- Comment #7 from Marcus Hüwe <suse-tux@gmx.de> 2008-01-25 14:29:18 MST --- *** Bug 355734 has been marked as a duplicate of this bug. *** https://bugzilla.novell.com/show_bug.cgi?id=355734 -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034 User suse-tux@gmx.de added comment https://bugzilla.novell.com/show_bug.cgi?id=280034#c8 Marcus Hüwe <suse-tux@gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adrian@novell.com --- Comment #8 from Marcus Hüwe <suse-tux@gmx.de> 2008-02-11 07:10:08 MST --- *** Bug 360430 has been marked as a duplicate of this bug. *** https://bugzilla.novell.com/show_bug.cgi?id=360430 -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034 User poeml@novell.com added comment https://bugzilla.novell.com/show_bug.cgi?id=280034#c9 --- Comment #9 from Peter Poeml <poeml@novell.com> 2008-04-25 04:43:24 MST --- The above scenarios have been fixed meanwhile: % osc buildinfo error: '.' is not an osc working copy % osc buildinfo openSUSE_10.2 nixmitarch HTTP Error 404: Not Found # after changing password or username in .oscrc (and removing cookies) % osc ci HTTP Error 401: Unauthorized # server not reachable: % osc ci Failed to reach a server: (111, 'Connection refused') # or for instance % osc ci Failed to reach a server: (-2, 'Name or service not known') # copypac with non-existing projects/packages: % osc copypac home:poeml apachestats foobar Sending meta data... HTTP Error 404: Not Found % osc copypac foo bar baz Error getting meta for project 'foo' package 'bar' HTTP Error 404: Not Found % osc copypac home:poeml bar baz Error getting meta for project 'home:poeml' package 'bar' HTTP Error 404: Not Found Marcus and I are working on a branch which is allowing to fix these things cleanly: https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exceptio... Substantial fixes have already gone there. Most common error paths can and will be fixed systematically now. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034 User poeml@novell.com added comment https://bugzilla.novell.com/show_bug.cgi?id=280034#c10 Peter Poeml <poeml@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |FIXED --- Comment #10 from Peter Poeml <poeml@novell.com> 2008-05-02 02:34:59 MST --- I'll close this as "fixed in svn". Thanks everyone for contributing in various ways! -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=280034 User suse-beta@cboltz.de added comment https://bugzilla.novell.com/show_bug.cgi?id=280034#c11 Christian Boltz <suse-beta@cboltz.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |VERIFIED --- Comment #11 from Christian Boltz <suse-beta@cboltz.de> 2008-08-10 14:53:07 MDT --- VERIFIED - osc-0.107-2.1 shows nice error messages instead of long backtraces. Tested with the two cases in the initial report. Thanks for fixing the error reporting! -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
participants (1)
-
bugzilla_noreply@novell.com