From 40bbe0c3793a2acacc3f9d73eadb738d1759d11f Mon Sep 17 00:00:00 2001 From: "kiko%async.com.br" <> Date: Fri, 16 Jul 2004 10:56:35 +0000 Subject: Additional fix for bug 244324: bugzilla-submit crashes when incorrect base url provided. Check other situations in which we may have trouble with bad base urls and report error conditions. contrib checkin. --- contrib/bugzilla-submit/bugzilla-submit | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'contrib/bugzilla-submit/bugzilla-submit') diff --git a/contrib/bugzilla-submit/bugzilla-submit b/contrib/bugzilla-submit/bugzilla-submit index d24fc3843..47c94b275 100755 --- a/contrib/bugzilla-submit/bugzilla-submit +++ b/contrib/bugzilla-submit/bugzilla-submit @@ -25,6 +25,11 @@ if map(int, version) < [2, 3]: import urllib, re, os, netrc, email.Parser, optparse +class ErrorURLopener(urllib.URLopener): + """URLopener that handles HTTP 404s""" + def http_error_404(self, url, fp, errcode, errmsg, headers, *extra): + raise ValueError, errmsg # 'File Not Found' + # Set up some aliases -- partly to hide the less friendly fieldnames # behind the names actually used for them in the stock web page presentation, # and partly to provide a place for mappings if the Bugzilla fieldnames @@ -186,7 +191,10 @@ def validate_fields(data): def submit_bug_POST(bugzilla, data): # Move the request over the wire postdata = urllib.urlencode(data) - url = urllib.urlopen("%s/post_bug.cgi" % bugzilla, postdata) + try: + url = ErrorURLopener().open("%s/post_bug.cgi" % bugzilla, postdata) + except ValueError: + error("Bugzilla site at %s not found (HTTP returned 404)" % bugzilla) ret = url.read() check_result_POST(ret, data) @@ -239,17 +247,20 @@ def check_result_POST(ret, data): error("keyword(s) %r not registered in " "this Bugzilla instance" % keywords) if ret.find("The product name") != -1: - error("Product %r does not exist in this " + error("product %r does not exist in this " "Bugzilla instance" % product) # XXX: this should be smarter if ret.find("does not exist") != -1: - error("Could not mark dependencies for bugs %s: one or " + error("could not mark dependencies for bugs %s: one or " "more bugs didn't exist in this Bugzilla instance" % deps) if ret.find("Match Failed") != -1: # XXX: invalid CC hits on this error too error("the bug assignee %r isn't registered in " "this Bugzilla instance" % assignee) # If all is well, return bug number posted + if ret.find("process_bug.cgi") == -1: + error("could not post bug to %s: are you sure this " + "is Bugzilla instance's top-level directory?" % bugzilla) m = re.search("Bug ([0-9]+) Submitted", ret) if not m: print ret -- cgit v1.2.3-24-g4f1b