Stop mangling error output.

This fixes #135 and #511.  Some exceptions, like a KeyError, could cause
the error output to become mangled.  To prevent this, we'll re-wrap the
error output in an Exception so that it can be formatted correctly by
the remaining layers.  A test has also been added to prevent further
regressions.