A structured Python exception with diagnostic output and actionable remediation hints.
Project description
๐ฏsimplibs-exception
An exception that tries to be a friend.
A structured Python exception framework that doesn't just crashโit explains what went wrong, why it happened, and how to fix it. Beautiful terminal layouts, programmatic analytics exporters, zero filler.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๏ธ VALIDATION ERROR: parameter age
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Expected: a positive integer
Got: -5 (int)
Problem: value is negative
File info: File: main.py | Line: 42 | Function: validate
File path: /path/to/project/main.py
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ง How to fix:
โข Provide a value greater than 0.
โข Use the int type.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งญ The Core Philosophy
Standard Python exceptions tell you where code broke, but they leave you guessing about what was inside your variables or how to recover. You end up stuffing complex debugging telemetry into ad-hoc f-strings.
simplibs-exception changes the paradigm. Instead of chaotic crashes,
you get diagnostic reports: highly structured, easily readable context
containing your expected vs. obtained values, specific problem statements,
and actionable remediation steps.
๐ฆ Installation
pip install simplibs-exception
โ ๏ธ Migration Note (v0.2.x โ v1.0.0+):
Please note that version1.0.0and above introduces a breaking change and is not backward compatible with previous releases. The parametervalue_labelinSimpleExceptionData(andSimpleException) has been renamed tolabelfor greater semantic precision and broader context applicability. If you are upgrading from an older version, please update your codebase accordingly.
๐ Quick Start in 60 Seconds
You can initialize SimpleException as an empty marker and enrich it incrementally.
All parameters are optional.
Level 1: The Marker
Just mark a failure pointโthe framework automatically captures file, line, and function context.
from simplibs.exception import SimpleException
raise SimpleException()
# โ ๏ธ ERROR: File: main.py | Line: 12 | Function: process
Level 2: Custom Text Message
Use it like a traditional exception but wrapped in cleaner console formatting.
raise SimpleException("Database connection timed out after 30s")
Level 3: The Full Diagnostic
Provide full structured data to turn a simple crash into an elite debugging card.
raise SimpleException(
label = "parameter age",
expected = "a positive integer",
value = age,
problem = "value is negative",
how_to_fix = "Provide a value greater than 0."
)
๐ ๏ธ The Architecture: 3 Pillars
To keep the library clean and highly optimized, the logic is separated into three decoupled components:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SimpleExceptionSettings โ โโโ Global configuration, overrides, and safety locks
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SimpleExceptionData โ โโโ Immutable data storage, serializers (.to_dict())
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SimpleException โ โโโ Active runtime manager, dynamic MRO, and execution
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. SimpleExceptionData (The Model)
Acts as the passive data schema. It owns the raw parameters, lazy caching properties,
and public analytics state exporters (to_dict(), to_json()).
โก๏ธ README_DATA.md
2. SimpleException (The Runtime Engine)
The active execution manager. It overrides dataclass-level __init__ routines,
manages dynamic Method Resolution Order (MRO) injection, triggers subclass compile-time audits,
and orchestrates terminal rendering.
โก๏ธ README_EXCEPTION.md
3. SimpleExceptionSettings (The Control Center)
A validated global configuration interface governed by a strict metaclass. It lets you customize default behaviors, set value truncation boundaries, and control stack trace filtering securely.
โก๏ธ README_SETTINGS.md
๐จ Output Modes
Your exception can speak different visual formats depending on your deployment environment:
PRETTY(Default): Beautifully framed visual card layout optimized for console output during development.SIMPLE: Plain-text structured layout without Unicode borders. Perfect for standard files and log processors.ONELINE: Everything compressed into a single line. Perfect for standard application log streaming.LOG: Highly optimized, machine-readablekey=valueformat designed for log forwarders (Datadog, Splunk, ELK).
โก๏ธ README_MODES.md
You can easily build your own layout formats (e.g., HTML, Slack message blocks) by subclassing the base template manager ModeBase.
โก๏ธ README_CUSTOM_MODES.md
๐งฐ Built-in Developer Tools
The framework provides helper functions to minimize repetitive error-handling boilerplate:
bool_or_exception
A bi-modal validation shortcut. It either gracefully returns False
or raises a fully-structured exception based on a flag, eliminating verbose conditional block code.
from simplibs.exception.tools import bool_or_exception
def validate_age(age: int, return_bool: bool = False) -> bool:
if age < 0:
return bool_or_exception(return_bool, value=age, label="age", expected="positive integer")
return True
โก๏ธ README_BOOL_OR_EXCEPTION.md
raise_with_location_offset
A single-line utility that takes any exception, dynamically shifts its stack trace tracking depth backwards, and raises it.
raise_with_location_offset(SimpleException("Failed"), offset=1)
โก๏ธ README_RAISE_WITN_LOCATION_OFFSET.md
@raise_location_offset (Decorator)
An Aspect-Oriented decorator that intercepts bubbling exceptions and re-targets their trace location to the caller's call-site. Excellent for writing transparent gatekeeper and validator helpers.
@raise_location_offset(offset=1)
def assert_positive(n: int):
if n <= 0:
raise SimpleException(value=n, expected="strictly positive")
โก๏ธ README_RAISE_LOCATION_OFFSET.md
๐งช Advanced Testing Ecosystem
Writing unit tests for custom exceptions, validation functions, and error parameters
often leads to repetitive boilerplate. To solve this, simplibs-exception includes
a complete, self-contained testing framework under its testing namespace.
With our testing tools, you can run bulk matrix-driven evaluations, validate class MRO integrity, and audit error payloads with minimal code:
from simplibs.exception.testing import assert_exception_class
# Automatically audits inheritance, defaults, constructors, and serialization protocols
assert_exception_class(MyCustomError)
โก๏ธ README_TESTING.md
โฏ๏ธ About simplibs
All libraries in the simplibs (Simple Libraries) ecosystem share a common engineering philosophy:
- Dyslexia-friendly: We actively minimize cognitive load. Code is atomized into small, self-contained units, files are named directly after the logical task they perform, and explanations describe why something is designed, not just what it is.
- Programmer's Zen: Nothing should be missing, and nothing should be superfluous. We value clean execution paths and robust, understandable code architectures over rushed, messy feature sets.
- Defensive Style: We actively anticipate edge cases and failure modes so that only safe operational paths remain. Our code is built to degrade gracefully rather than crash unexpectedly.
- Minimalism: Find the most direct path to the goal in as few operational steps as possible without taking shortcuts on safety, readability, or completeness.
- Code as Craft: Code should be pleasant to look at, readable at a glance, and evoke structural harmony. We treat software engineering as a precision trade.
๐ค Contributing & Community
This is an open-source project built with love and care. We strongly believe in community collaboration and welcome any feedback, bug reports, or feature ideas!
- Want to contribute? Feel free to open an Issue or submit a Pull Request.
- Want to get in touch? If you'd like to discuss the project further, collaborate, or just say hello, feel free to open a GitHub Issue or start a Discussion.
๐ License
This library is released under the MIT License. Build great things!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simplibs_exception-1.0.0.tar.gz.
File metadata
- Download URL: simplibs_exception-1.0.0.tar.gz
- Upload date:
- Size: 105.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7495a44e33345a42d5b46af4791b4afe6df1d873896f9574ffcd90660b19be9
|
|
| MD5 |
1428c9529b7f8c16d74edf0ccebff669
|
|
| BLAKE2b-256 |
f2d60838d982e4fee253876380711aa65c08930e51207a933e86c73227a11879
|
File details
Details for the file simplibs_exception-1.0.0-py3-none-any.whl.
File metadata
- Download URL: simplibs_exception-1.0.0-py3-none-any.whl
- Upload date:
- Size: 159.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5813c84fd6b56d1129621819d90f537353abe360ee7164ec567759979e972ea
|
|
| MD5 |
e8beaeec3558233c346130aa3d7a85bb
|
|
| BLAKE2b-256 |
62b2eddd34ee7ec0572d3561dee393dfaa62deb5168bb653325193f62a8354d4
|