diff options
author | Georg Brandl <georg@python.org> | 2009-02-24 19:15:39 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-02-24 19:15:39 +0100 |
commit | 9ed275c868c97786c25668cd87ed3fbc8e862f15 (patch) | |
tree | 1b2aea56342f65c6bc202b9824ed7b2c93f583d0 /sphinx/errors.py | |
parent | fb511a015aa47c943c5dc1286f58743fca307b1c (diff) | |
download | sphinx-git-9ed275c868c97786c25668cd87ed3fbc8e862f15.tar.gz |
#109: fix circular import problems by moving exceptions into their own module.
Diffstat (limited to 'sphinx/errors.py')
-rw-r--r-- | sphinx/errors.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/sphinx/errors.py b/sphinx/errors.py new file mode 100644 index 000000000..d9b8b6b87 --- /dev/null +++ b/sphinx/errors.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +""" + sphinx.errors + ~~~~~~~~~~~~~ + + Contains SphinxError and a few subclasses (in an extra module to avoid + circular import problems). + + :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +class SphinxError(Exception): + """ + Base class for Sphinx errors that are shown to the user in a nicer + way than normal exceptions. + """ + category = 'Sphinx error' + + +class SphinxWarning(SphinxError): + """Raised for warnings if warnings are treated as errors.""" + category = 'Warning, treated as error' + + +class ExtensionError(SphinxError): + """Raised if something's wrong with the configuration.""" + category = 'Extension error' + + def __init__(self, message, orig_exc=None): + super(ExtensionError, self).__init__(message) + self.orig_exc = orig_exc + + def __repr__(self): + if self.orig_exc: + return '%s(%r, %r)' % (self.__class__.__name__, + self.message, self.orig_exc) + return '%s(%r)' % (self.__class__.__name__, self.message) + + def __str__(self): + parent_str = super(ExtensionError, self).__str__() + if self.orig_exc: + return '%s (exception: %s)' % (parent_str, self.orig_exc) + return parent_str + + +class ThemeError(SphinxError): + category = 'Theme error' |