Print exception tracebacks.

This commit is contained in:
Bastian Kleineidam 2013-03-25 19:39:37 +01:00
parent 1314da3ffb
commit 01c2afc264
2 changed files with 17 additions and 6 deletions

10
dosage
View file

@ -120,7 +120,7 @@ def saveComicStrip(strip, basepath):
if saved:
allskipped = False
except Exception as msg:
out.error('Could not save image at %s to %s: %s' % (image.referrer, image.filename, msg))
out.exception('Could not save image at %s to %s: %s' % (image.referrer, image.filename, msg))
errors += 1
return errors, allskipped
@ -131,7 +131,7 @@ def displayHelp(comics):
for scraperobj in getScrapers(comics):
displayComicHelp(scraperobj)
except ValueError as msg:
out.error(msg)
out.exception(msg)
return 1
return 0
@ -155,14 +155,14 @@ def getComics(options):
"""Retrieve comics."""
errors = 0
if options.handler:
for name in options.handler:
for name in set(options.handler):
events.addHandler(name, options.basepath, options.baseurl)
events.getHandler().start()
try:
for scraperobj in getScrapers(options.comic, options.basepath, options.adult, options.multimatch):
errors += getStrips(scraperobj, options)
except ValueError as msg:
out.error(msg)
out.exception(msg)
errors += 1
finally:
events.getHandler().end()
@ -189,7 +189,7 @@ def getStrips(scraperobj, options):
out.info("Stop retrieval because image file already exists")
break
except Exception as msg:
out.error(msg)
out.exception(msg)
errors += 1
finally:
out.context = ''

View file

@ -5,6 +5,7 @@ import time
import sys
import os
import threading
import traceback
from .ansicolor import Colorizer
lock = threading.Lock()
@ -35,9 +36,19 @@ class Output(object):
"""Write a warning message."""
self.write("WARN: %s" % s, color='bold;yellow')
def error(self, s):
def error(self, s, tb=None):
"""Write an error message."""
self.write("ERROR: %s" % s, color='light;red')
#if tb is not None:
# self.write('Traceback (most recent call last):', 1)
def exception(self, s):
"""Write error message with traceback info."""
self.error(s)
type, value, tb = sys.exc_info()
self.writelines(traceback.format_stack(), 1)
self.writelines(traceback.format_tb(tb)[1:], 1)
self.writelines(traceback.format_exception_only(type, value), 1)
def write(self, s, level=0, color=None):
"""Write message with indentation, context and optional timestamp."""