Add showtracebacks option.
authorAdam Sampson <ats@offog.org>
Tue, 22 Dec 2009 15:51:47 +0000 (15:51 +0000)
committerAdam Sampson <ats@offog.org>
Tue, 22 Dec 2009 15:51:47 +0000 (15:51 +0000)
NEWS
config
rawdoglib/rawdog.py

diff --git a/NEWS b/NEWS
index 396f60e81545b9304013e6f4d845e031fb5f93c0..96625930960bf2e54e5dfbd1544f20573642e2a2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ Decode the config file from the system encoding, and escape "define_"d
 strings when they're written to the output file (reported by Cristian
 Rigamonti).
 
+Add the "showtracebacks" option, which causes exceptions that occur
+while a feed is being fetched to be reported with a traceback in the
+resulting error message.
+
 - rawdog 2.12
 
 Make rawdog work with Python 2.6 (reported by Roy Lanek).
diff --git a/config b/config
index 6a106f6f518398d3466fbd86ccbaa1d84ad96f9b..f1110573f4f1c9ad210f6f5c5756bfed4f68be22 100644 (file)
--- a/config
+++ b/config
@@ -164,6 +164,11 @@ timeout 30s
 # errors; if this is true, rawdog will silently ignore them.
 ignoretimeouts false
 
+# Whether to show Python traceback messages. If this is true, rawdog will show
+# a traceback message if an exception is thrown while fetching a feed; this is
+# mostly useful for debugging rawdog or feedparser.
+showtracebacks false
+
 # Whether to display verbose status messages saying what rawdog's doing
 # while it runs. Specifying -v or --verbose on the command line is
 # equivalent to saying "verbose true" here.
index 749af97d825257ef4a570064ac9dd03c634ca5ab..221b365e0970cc0c1fc47e37477229b978755591 100644 (file)
@@ -359,23 +359,27 @@ class Feed:
                                handlers = handlers,
                                auth_creds = auth_creds,
                                use_im = use_im)
-               except:
-                       return None
+               except Exception, e:
+                       return {
+                               "rawdog_exception": e,
+                               "rawdog_traceback": sys.exc_info()[2],
+                               }
 
        def update(self, rawdog, now, config, articles, p):
                """Add new articles from a feed to the collection.
                Returns True if any articles were read, False otherwise."""
 
-               status = None
-               if p is not None:
-                       status = p.get("status")
+               status = p.get("status")
                self.last_update = now
 
                error = None
                non_fatal = False
                old_url = self.url
-               if p is None:
-                       error = "Error fetching or parsing feed."
+               if "rawdog_exception" in p:
+                       error = "Error fetching or parsing feed: %s" % str(p["rawdog_exception"])
+                       if config["showtracebacks"]:
+                               from traceback import format_tb
+                               error += "\n" + "".join(format_tb(p["rawdog_traceback"]))
                elif status is None and len(p["feed"]) == 0:
                        if config["ignoretimeouts"]:
                                return False
@@ -677,6 +681,7 @@ class Config:
                        "itemtemplate" : "default",
                        "verbose" : 0,
                        "ignoretimeouts" : 0,
+                       "showtracebacks" : 0,
                        "daysections" : 1,
                        "timesections" : 1,
                        "blocklevelhtml" : 1,
@@ -785,6 +790,8 @@ class Config:
                        self["verbose"] = parse_bool(l[1])
                elif l[0] == "ignoretimeouts":
                        self["ignoretimeouts"] = parse_bool(l[1])
+               elif l[0] == "showtracebacks":
+                       self["showtracebacks"] = parse_bool(l[1])
                elif l[0] == "daysections":
                        self["daysections"] = parse_bool(l[1])
                elif l[0] == "timesections":