From dafe8581c0a9996f3d5577a899aa35789ec95b3a Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 22 Dec 2009 15:51:47 +0000 Subject: [PATCH] Add showtracebacks option. --- NEWS | 4 ++++ config | 5 +++++ rawdoglib/rawdog.py | 21 ++++++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 396f60e..9662593 100644 --- 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 6a106f6..f111057 100644 --- 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. diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 749af97..221b365 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -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": -- 2.35.1