Commit 3924c28b authored by ben's avatar ben

Added better logging for check_common_error - now it should be clearer

which file was being processed when error occurred.


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@218 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 43b7489a
...@@ -145,11 +145,14 @@ class Logger: ...@@ -145,11 +145,14 @@ class Logger:
Main.cleanup() Main.cleanup()
sys.exit(1) sys.exit(1)
def exception_to_string(self): def exception_to_string(self, arglist = []):
"""Return string version of current exception""" """Return string version of current exception plus what's in arglist"""
type, value, tb = sys.exc_info() type, value, tb = sys.exc_info()
return ("Exception '%s' raised of class '%s':\n%s" % s = ("Exception '%s' raised of class '%s':\n%s" %
(value, type, "".join(traceback.format_tb(tb)))) (value, type, "".join(traceback.format_tb(tb))))
if arglist:
s += "__Arguments:\n" + "\n".join(map(str, arglist))
return s
def exception(self, only_terminal = 0, verbosity = 5): def exception(self, only_terminal = 0, verbosity = 5):
"""Log an exception and traceback """Log an exception and traceback
......
...@@ -255,7 +255,7 @@ class Robust: ...@@ -255,7 +255,7 @@ class Robust:
except (EnvironmentError, SkipFileException, DSRPPermError, except (EnvironmentError, SkipFileException, DSRPPermError,
RPathException, Rdiff.RdiffException, RPathException, Rdiff.RdiffException,
librsync.librsyncError, C.UnknownFileTypeError), exc: librsync.librsyncError, C.UnknownFileTypeError), exc:
TracebackArchive.add() TracebackArchive.add([function] + args)
if (not isinstance(exc, EnvironmentError) or if (not isinstance(exc, EnvironmentError) or
(errno.errorcode[exc[0]] in (errno.errorcode[exc[0]] in
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST', ['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
...@@ -300,9 +300,14 @@ class SignalException(Exception): ...@@ -300,9 +300,14 @@ class SignalException(Exception):
class TracebackArchive: class TracebackArchive:
"""Save last 10 caught exceptions, so they can be printed if fatal""" """Save last 10 caught exceptions, so they can be printed if fatal"""
_traceback_strings = [] _traceback_strings = []
def add(cls): def add(cls, extra_args = []):
"""Add most recent exception to archived list""" """Add most recent exception to archived list
cls._traceback_strings.append(Log.exception_to_string())
If extra_args are present, convert to strings and add them as
extra information to same traceback archive.
"""
cls._traceback_strings.append(Log.exception_to_string(extra_args))
if len(cls._traceback_strings) > 10: if len(cls._traceback_strings) > 10:
cls._traceback_strings = cls._traceback_strings[:10] cls._traceback_strings = cls._traceback_strings[:10]
......
...@@ -145,11 +145,14 @@ class Logger: ...@@ -145,11 +145,14 @@ class Logger:
Main.cleanup() Main.cleanup()
sys.exit(1) sys.exit(1)
def exception_to_string(self): def exception_to_string(self, arglist = []):
"""Return string version of current exception""" """Return string version of current exception plus what's in arglist"""
type, value, tb = sys.exc_info() type, value, tb = sys.exc_info()
return ("Exception '%s' raised of class '%s':\n%s" % s = ("Exception '%s' raised of class '%s':\n%s" %
(value, type, "".join(traceback.format_tb(tb)))) (value, type, "".join(traceback.format_tb(tb))))
if arglist:
s += "__Arguments:\n" + "\n".join(map(str, arglist))
return s
def exception(self, only_terminal = 0, verbosity = 5): def exception(self, only_terminal = 0, verbosity = 5):
"""Log an exception and traceback """Log an exception and traceback
......
...@@ -255,7 +255,7 @@ class Robust: ...@@ -255,7 +255,7 @@ class Robust:
except (EnvironmentError, SkipFileException, DSRPPermError, except (EnvironmentError, SkipFileException, DSRPPermError,
RPathException, Rdiff.RdiffException, RPathException, Rdiff.RdiffException,
librsync.librsyncError, C.UnknownFileTypeError), exc: librsync.librsyncError, C.UnknownFileTypeError), exc:
TracebackArchive.add() TracebackArchive.add([function] + args)
if (not isinstance(exc, EnvironmentError) or if (not isinstance(exc, EnvironmentError) or
(errno.errorcode[exc[0]] in (errno.errorcode[exc[0]] in
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST', ['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
...@@ -300,9 +300,14 @@ class SignalException(Exception): ...@@ -300,9 +300,14 @@ class SignalException(Exception):
class TracebackArchive: class TracebackArchive:
"""Save last 10 caught exceptions, so they can be printed if fatal""" """Save last 10 caught exceptions, so they can be printed if fatal"""
_traceback_strings = [] _traceback_strings = []
def add(cls): def add(cls, extra_args = []):
"""Add most recent exception to archived list""" """Add most recent exception to archived list
cls._traceback_strings.append(Log.exception_to_string())
If extra_args are present, convert to strings and add them as
extra information to same traceback archive.
"""
cls._traceback_strings.append(Log.exception_to_string(extra_args))
if len(cls._traceback_strings) > 10: if len(cls._traceback_strings) > 10:
cls._traceback_strings = cls._traceback_strings[:10] cls._traceback_strings = cls._traceback_strings[:10]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment