Skip to main content

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

You can install the package from PyPI

$ pip install tsl-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

Release files for tsl-prettyexc 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tsl-prettyexc 0.5.2
File Size Uploaded
tsl-prettyexc-0.5.2.tar.gz 6.3 kB Details

Release files / tsl-prettyexc-0.5.2.tar.gz

Download URL tsl-prettyexc-0.5.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3b0d9c80c8ecd34253652c3949dbf50cd2dee46112eff1a027bb0757897a7432
BLAKE2b-256 checksum
How to use checksums
b134bc3fea486b36eacb9b178943a5df0fb96c6b7308b6229b5446e638f0d7f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page