Skip to main content

Toolkit for human-friendly exception interface.

Project description

https://travis-ci.org/youknowone/prettyexc.svg?branch=master

prettyexc provides common exception representation to make human-readable exception in easy way.

You can install the package from PyPI

$ pip install prettyexc

Example

Prelude::
>>> from prettyexc import PrettyException
Put and get your arguments always::
>>> class SimpleException(PrettyException):
...     pass
...
>>> e = SimpleException('any', 'plain', 'args', code=200, description='OK')
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.SimpleException: "any","plain","args",code=200,description="OK"
SimpleException("any","plain","args",code=200,description="OK")
>>> print [e, e]
[<SimpleException("any","plain","args",code=200,description="OK")>, <SimpleException("any","plain","args",code=200,description="OK")>]
Set default message::
>>> class MessageException(PrettyException):
...     message = u'You should select a user'
...
>>> e = MessageException(user_id=10)
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.MessageException: You should select a user
>>> print [e, e]
[<MessageException(user_id=10)>, <MessageException(user_id=10)>]
Set message formatter::
>>> class FormatException(PrettyException):
...     message_format = u'User {user_id} has no permission.'
...
>>> e = FormatException(user_id=10)
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.FormatException: User 10 has no permission.
>>> print e.message
User 10 has no permission.
Patch existing exceptions::
>>> from prettyexc import patch
>>> class AnException(Exception): pass
...
>>> patch(AnException, PrettyException)
>>> raise AnException(status=404)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.AnException: status=404

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prettyexc-0.6.0.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file prettyexc-0.6.0.tar.gz.

File metadata

  • Download URL: prettyexc-0.6.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prettyexc-0.6.0.tar.gz
Algorithm Hash digest
SHA256 4187ad20fdf6f61188cf9ef5c7822342f55a6475afdbc96e4dcee432d6dbbdec
MD5 2c3f6329cdf8f625d11b4cec5ad912f0
BLAKE2b-256 326a3334c590ceffb591546140b403a9ec207f69690229a15f83db5f7eb651f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page