skip to navigation
skip to content

delfick_error 1.4

Customized Exception class

Latest Version: 1.7.2

This is an error class that I keep remaking in projects


The point of this exception class is to be able to create an error class that automatically combines keyword arguments given to the exception instance:

>>> from delfick_error import DelfickError
>>> DelfickError()
>>> str(DelfickError())
>>> str(DelfickError("blah"))
>>> str(DelfickError("blah", a=1, b=2))

You can also subclass DelfickError and override the description of the error:

>>> class AnError(DelfickError):
...  desc = "An error specific to something"
>>> AnError()
>>> str(AnError("things"))
'"An error specific to something. things"'
>>> str(AnError("things", a=1, b=2))
'"An error specific to something. things"\ta=1\tb=2'

You can also use it to display multiple errors:

>>> ex1 = ValueError("Bad value")
>>> ex2 = IndexError("Bad index")
>>> ex3 = Exception("blah")
>>> str(AnError("found errors", _errors=[ex1, ex2, ex3]))
'"An error specific to something. found errors"\nerrors:\n\tBad value\n\tBad index\n\tblah'
>>> print str(AnError("found errors", _errors=[ex1, ex2, ex3]))
"An error specific to something. found errors"
        Bad value
        Bad index

Here, the _errors argument is interpreted using special logic to put each item in it’s list on a new line.

DelfickError also has a mechanism to allow you to control how the error is formatted when converting the error to a string.

>>> class SomeObject(object):
...   def __init__(self, val):
...     self.val = val
...   def delfick_error_format(self, key):
...     return "{0}_formatted_{1}".format(self.val, key)
>>> obj = SomeObject(20)
>>> str(DelfickError(a=1, b=obj))


Fixed an embarrassing bug

Made DelfickError Orderable

Added an assertIs shim to DelfickErrorTestMixin

Tests work in python26, python27 and python34

Now with tests!

And DelfickErrorTestMixin for your testing pleasure

Initial release


Use pip!:

pip install delfick_error

Or if you’re developing it:

pip install -e .
pip install -e ".[tests]"


To run the tests in this project, just use the helpful script:


Or run tox:

File Type Py Version Uploaded on Size
delfick_error-1.4.tar.gz (md5) Source 2014-08-23 4KB
  • Downloads (All Versions):
  • 44 downloads in the last day
  • 377 downloads in the last week
  • 1802 downloads in the last month