simple-exception 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. simple_exception-0.1.0/LICENSE +21 -0
  2. simple_exception-0.1.0/PKG-INFO +525 -0
  3. simple_exception-0.1.0/README.md +498 -0
  4. simple_exception-0.1.0/pyproject.toml +52 -0
  5. simple_exception-0.1.0/setup.cfg +4 -0
  6. simple_exception-0.1.0/src/simple_exception/__init__.py +46 -0
  7. simple_exception-0.1.0/src/simple_exception/core/__init__.py +20 -0
  8. simple_exception-0.1.0/src/simple_exception/core/_internal_exception/SimpleExceptionInternalError.py +91 -0
  9. simple_exception-0.1.0/src/simple_exception/core/_internal_exception/__init__.py +16 -0
  10. simple_exception-0.1.0/src/simple_exception/core/data/SimpleExceptionData.py +115 -0
  11. simple_exception-0.1.0/src/simple_exception/core/data/__init__.py +15 -0
  12. simple_exception-0.1.0/src/simple_exception/exception/SimpleException.py +220 -0
  13. simple_exception-0.1.0/src/simple_exception/exception/__init__.py +27 -0
  14. simple_exception-0.1.0/src/simple_exception/exception/_mixins/__init__.py +43 -0
  15. simple_exception-0.1.0/src/simple_exception/exception/_mixins/dunders/InitSubclass.py +60 -0
  16. simple_exception-0.1.0/src/simple_exception/exception/_mixins/dunders/New.py +136 -0
  17. simple_exception-0.1.0/src/simple_exception/exception/_mixins/dunders/__init__.py +15 -0
  18. simple_exception-0.1.0/src/simple_exception/exception/_mixins/dunders/_utils/__init__.py +14 -0
  19. simple_exception-0.1.0/src/simple_exception/exception/_mixins/dunders/_utils/check_children_class_attributes.py +143 -0
  20. simple_exception-0.1.0/src/simple_exception/exception/_mixins/normalizers/NormalizeParam.py +61 -0
  21. simple_exception-0.1.0/src/simple_exception/exception/_mixins/normalizers/ProcessExceptionParam.py +86 -0
  22. simple_exception-0.1.0/src/simple_exception/exception/_mixins/normalizers/ProcessGetLocationParam.py +57 -0
  23. simple_exception-0.1.0/src/simple_exception/exception/_mixins/normalizers/ProcessHowToFixParam.py +80 -0
  24. simple_exception-0.1.0/src/simple_exception/exception/_mixins/normalizers/ProcessSkipLocationsParam.py +67 -0
  25. simple_exception-0.1.0/src/simple_exception/exception/_mixins/normalizers/__init__.py +23 -0
  26. simple_exception-0.1.0/src/simple_exception/exception/_mixins/serializers/ToDebugDict.py +89 -0
  27. simple_exception-0.1.0/src/simple_exception/exception/_mixins/serializers/ToDict.py +53 -0
  28. simple_exception-0.1.0/src/simple_exception/exception/_mixins/serializers/ToJson.py +38 -0
  29. simple_exception-0.1.0/src/simple_exception/exception/_mixins/serializers/__init__.py +17 -0
  30. simple_exception-0.1.0/src/simple_exception/modes/LOG.py +105 -0
  31. simple_exception-0.1.0/src/simple_exception/modes/ONELINE.py +94 -0
  32. simple_exception-0.1.0/src/simple_exception/modes/PRETTY.py +150 -0
  33. simple_exception-0.1.0/src/simple_exception/modes/SIMPLE.py +105 -0
  34. simple_exception-0.1.0/src/simple_exception/modes/__init__.py +32 -0
  35. simple_exception-0.1.0/src/simple_exception/modes/base_class/ModeBase.py +192 -0
  36. simple_exception-0.1.0/src/simple_exception/modes/base_class/__init__.py +13 -0
  37. simple_exception-0.1.0/src/simple_exception/modes/base_class/_mixins/PrintCallerInfo.py +84 -0
  38. simple_exception-0.1.0/src/simple_exception/modes/base_class/_mixins/PrintIntroLine.py +46 -0
  39. simple_exception-0.1.0/src/simple_exception/modes/base_class/_mixins/PrintValueWithType.py +56 -0
  40. simple_exception-0.1.0/src/simple_exception/modes/base_class/_mixins/__init__.py +18 -0
  41. simple_exception-0.1.0/src/simple_exception/modes/base_class/_validations/SimpleExceptionModeError.py +30 -0
  42. simple_exception-0.1.0/src/simple_exception/modes/base_class/_validations/__init__.py +17 -0
  43. simple_exception-0.1.0/src/simple_exception/modes/base_class/_validations/validate_has_simple_exception_data.py +44 -0
  44. simple_exception-0.1.0/src/simple_exception/settings/SimpleExceptionSettings.py +115 -0
  45. simple_exception-0.1.0/src/simple_exception/settings/__init__.py +23 -0
  46. simple_exception-0.1.0/src/simple_exception/settings/_meta/SimpleExceptionSettingsMeta.py +76 -0
  47. simple_exception-0.1.0/src/simple_exception/settings/_meta/__init__.py +16 -0
  48. simple_exception-0.1.0/src/simple_exception/settings/_meta/validations/SimpleExceptionSettingsError.py +30 -0
  49. simple_exception-0.1.0/src/simple_exception/settings/_meta/validations/__init__.py +22 -0
  50. simple_exception-0.1.0/src/simple_exception/settings/_meta/validations/validate_dynamic_cls_cache.py +33 -0
  51. simple_exception-0.1.0/src/simple_exception/settings/_meta/validations/validate_get_location.py +26 -0
  52. simple_exception-0.1.0/src/simple_exception/settings/_meta/validations/validate_location_blacklist.py +48 -0
  53. simple_exception-0.1.0/src/simple_exception/settings/_meta/validations/validate_message_mode.py +28 -0
  54. simple_exception-0.1.0/src/simple_exception/utils/__init__.py +27 -0
  55. simple_exception-0.1.0/src/simple_exception/utils/caller_info/__init__.py +22 -0
  56. simple_exception-0.1.0/src/simple_exception/utils/caller_info/extract_caller_info.py +130 -0
  57. simple_exception-0.1.0/src/simple_exception/utils/exception_helper/__init__.py +21 -0
  58. simple_exception-0.1.0/src/simple_exception/utils/exception_helper/bool_or_exception.py +66 -0
  59. simple_exception-0.1.0/src/simple_exception/utils/sentinel/UNSET.py +72 -0
  60. simple_exception-0.1.0/src/simple_exception/utils/sentinel/__init__.py +14 -0
  61. simple_exception-0.1.0/src/simple_exception.egg-info/PKG-INFO +525 -0
  62. simple_exception-0.1.0/src/simple_exception.egg-info/SOURCES.txt +64 -0
  63. simple_exception-0.1.0/src/simple_exception.egg-info/dependency_links.txt +1 -0
  64. simple_exception-0.1.0/src/simple_exception.egg-info/requires.txt +3 -0
  65. simple_exception-0.1.0/src/simple_exception.egg-info/top_level.txt +1 -0
  66. simple_exception-0.1.0/tests/test_integration.py +211 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dalibor Sova (Sudip2708)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,525 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple-exception
3
+ Version: 0.1.0
4
+ Summary: A structured Python exception with diagnostic output and actionable remediation hints.
5
+ Author-email: "Dalibor Sova (Sudip2708)" <daliborsova@seznam.cz>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/simple-libs/simple-exception
8
+ Project-URL: Repository, https://github.com/simple-libs/simple-exception
9
+ Project-URL: Issues, https://github.com/simple-libs/simple-exception/issues
10
+ Project-URL: Changelog, https://github.com/simple-libs/simple-exception/blob/main/CHANGELOG.md
11
+ Keywords: exception,error,debugging,diagnostics,developer-tools
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Topic :: Software Development :: Debuggers
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # simple-exception
29
+
30
+ > An exception that tries to be a friend. A structured exception with diagnostic
31
+ > output, allowing you to describe the cause of an error, the circumstances of
32
+ > its occurrence, and the path to a fix. Fully compatible with standard Python
33
+ > exceptions — it simply extends them with more possibilities.
34
+
35
+ ![Python](https://img.shields.io/badge/python-3.11%2B-blue)
36
+ ![Licence](https://img.shields.io/badge/licence-MIT-green)
37
+ ![PyPI](https://img.shields.io/pypi/v/simple-exception)
38
+
39
+ ```
40
+ ═════════════════════════════════════════════════════════════════
41
+ ⚠️ VALIDATION ERROR: parameter age
42
+ ═════════════════════════════════════════════════════════════════
43
+ Expected: a positive integer
44
+ Got: -5 (int)
45
+ Problem: value is negative
46
+ File info: File: main.py | Line: 42 | Path: ... | Function: validate
47
+ ─────────────────────────────────────────────────────────────────
48
+ 🔧 How to fix:
49
+ • Provide a value greater than 0.
50
+ • Use the int type.
51
+ ═════════════════════════════════════════════════════════════════
52
+ ```
53
+
54
+ ---
55
+
56
+ ## Contents
57
+
58
+ - [Installation](#installation)
59
+ - [Quick start](#quick-start)
60
+ - [Parameters](#parameters)
61
+ - [Custom exceptions](#custom-exceptions)
62
+ - [Output modes](#output-modes)
63
+ - [Global settings](#global-settings)
64
+ - [Custom mode](#custom-mode)
65
+ - [Serialisation](#serialisation)
66
+ - [Utils](#utils)
67
+ - [About the Simple ecosystem](#about-the-simple-ecosystem)
68
+
69
+ ---
70
+
71
+ ## Installation
72
+
73
+ ```bash
74
+ pip install simple-exception
75
+ ```
76
+
77
+ ```python
78
+ from simple_exception import SimpleException
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Quick start
84
+
85
+ Python exceptions are a powerful tool — but their default output is terse.
86
+ We see *where* the error occurred, but not *what* exactly failed, *why* it
87
+ failed, or *how to fix it*. `SimpleException` changes that — on one hand it
88
+ works exactly like a regular Python exception, but it also gives you the option
89
+ of richer content for detailed diagnostics and actionable remediation. No
90
+ parameter is required, so you can start with nothing and add detail as needed.
91
+
92
+ ### Empty call — location only
93
+
94
+ Useful during rapid development when you just want to know *where* an exception
95
+ occurred without worrying about its content yet. Mark the spot and come back
96
+ to it later:
97
+
98
+ ```python
99
+ raise SimpleException()
100
+ # ═══════════════════════════════════════════════════════════════════
101
+ # ⚠️ ERROR: File: main.py | Line: 42 | Path: ... | Function: validate
102
+ # ═══════════════════════════════════════════════════════════════════
103
+ ```
104
+
105
+ ### Message only — like a classic exception
106
+
107
+ If you don't need structure — or just want to jot down an initial thought and
108
+ fill in the details later — `SimpleException` behaves exactly like `Exception`,
109
+ but with a nicer default output:
110
+
111
+ ```python
112
+ raise SimpleException("Database connection failed")
113
+ # ═══════════════════════════════════════════════════════════════════
114
+ # ⚠️ ERROR: Database connection failed
115
+ # File: main.py | Line: 15 | Path: ... | Function: connect
116
+ # ═══════════════════════════════════════════════════════════════════
117
+ ```
118
+
119
+ ### Full structured use
120
+
121
+ This is where the real power of the library shows — the exception communicates,
122
+ it doesn't just announce. You have full freedom over what you report and which
123
+ parameters you use. For the exception to be truly useful, it's worth filling
124
+ in the core parameters and especially `how_to_fix` — but none of it is
125
+ required:
126
+
127
+ ```python
128
+ raise SimpleException(
129
+ value_label = "parameter age",
130
+ expected = "a positive integer",
131
+ value = age,
132
+ problem = "value is negative",
133
+ how_to_fix = "Provide a value greater than 0.",
134
+ )
135
+ # ═══════════════════════════════════════════════════════════════════
136
+ # ⚠️ ERROR: parameter age
137
+ # ═══════════════════════════════════════════════════════════════════
138
+ # Expected: a positive integer
139
+ # Got: -5 (int)
140
+ # Problem: value is negative
141
+ # File info: File: main.py | Line: 42 | Path: ... | Function: validate
142
+ # ───────────────────────────────────────────────────────────────────
143
+ # 🔧 How to fix:
144
+ # • Provide a value greater than 0.
145
+ # ═══════════════════════════════════════════════════════════════════
146
+ ```
147
+
148
+ ---
149
+
150
+ ## Parameters
151
+
152
+ An overview of all parameters available when raising the exception. All are
153
+ optional — the exception works without any of them (see above).
154
+
155
+ | Parameter | Type | Description |
156
+ |-----------------|---------------------------|----------------------------------------------------------------|
157
+ | `message` | `str` | Free-form message — an alternative to the structured fields |
158
+ | `value` | `object` | The value that caused the exception |
159
+ | `value_label` | `str` | Human-readable label for the value (e.g. `"parameter age"`) |
160
+ | `expected` | `str` | What was expected |
161
+ | `problem` | `str` | What is wrong |
162
+ | `context` | `str` | Additional context — only include if it adds meaningful info |
163
+ | `how_to_fix` | `str \| tuple[str, ...]` | Tips on how to fix the error — one or more |
164
+ | `error_name` | `str` | Error name in the output (default: `"ERROR"`) |
165
+ | `exception` | `type[Exception]` | Exception class dynamically added to the instance ancestors |
166
+ | `get_location` | `bool \| int` | Enable/disable or set stack depth for location (default: `True`) |
167
+ | `skip_locations`| `tuple[str, ...]` | File path patterns to skip when resolving the call location |
168
+ | `oneline` | `bool` | Single-line output for this specific call |
169
+
170
+ ### More about the `exception` parameter
171
+
172
+ The `exception` parameter allows you to pass a specific Python exception into
173
+ the ancestors of the instance. The raised exception will then be catchable as
174
+ that specific type — without requiring static inheritance:
175
+
176
+ ```python
177
+ # As a class — the exception behaves as a ValueError
178
+ raise SimpleException(exception=ValueError, problem="negative value")
179
+
180
+ # From an except block — pass the instance directly
181
+ try:
182
+ int("abc")
183
+ except ValueError as e:
184
+ raise SimpleException(exception=e, problem="could not convert to int")
185
+
186
+ # Verify catchability
187
+ try:
188
+ raise SimpleException(exception=ValueError)
189
+ except ValueError:
190
+ print("caught as ValueError ✓")
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Custom exceptions
196
+
197
+ `SimpleException` can serve as the base for your own exception classes — for
198
+ example for a specific validation domain. You define the shared default
199
+ interface once, so that callers don't have to repeat the same parameters every
200
+ time:
201
+
202
+ ```python
203
+ from simple_exception import SimpleException
204
+
205
+ class AgeError(SimpleException):
206
+ error_name = "VALIDATION ERROR"
207
+ expected = "a positive integer"
208
+ how_to_fix = (
209
+ "Provide a value greater than 0.",
210
+ "Use the int type.",
211
+ )
212
+
213
+ # At the call site, only the specific values are needed —
214
+ # error_name, expected and how_to_fix are inherited from the class
215
+ raise AgeError(value=age, value_label="parameter age")
216
+ # ═══════════════════════════════════════════════════════════════════
217
+ # ⚠️ VALIDATION ERROR: parameter age
218
+ # ═══════════════════════════════════════════════════════════════════
219
+ # Expected: a positive integer
220
+ # Got: -5 (int)
221
+ # File info: File: main.py | Line: 8 | Path: ... | Function: validate_age
222
+ # ───────────────────────────────────────────────────────────────────
223
+ # 🔧 How to fix:
224
+ # • Provide a value greater than 0.
225
+ # • Use the int type.
226
+ # ═══════════════════════════════════════════════════════════════════
227
+
228
+ # Class-level attributes can always be overridden at the call site —
229
+ # the class definition is a default state, not a constraint
230
+ raise AgeError(
231
+ value = age,
232
+ value_label = "user age",
233
+ expected = "a number between 18 and 120", # overrides the class default
234
+ )
235
+ ```
236
+
237
+ The library automatically validates every subclass at definition time —
238
+ checking for typos and incorrect attribute types. The error surfaces
239
+ immediately on import, not somewhere at runtime:
240
+
241
+ ```python
242
+ class BadError(SimpleException):
243
+ expekted = "a positive integer" # typo in the attribute name
244
+ # → INTERNAL ERROR on import — the typo is caught immediately
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Output modes
250
+
251
+ The library provides four output modes. The default is `PRETTY` — a structured
252
+ output framed with separator lines. The mode can be changed globally via
253
+ settings or overridden for a single call using `oneline=True`.
254
+
255
+ | Mode | Description |
256
+ |-----------|-----------------------------------------------------------------------|
257
+ | `PRETTY` | Structured output with double separator lines — the default mode |
258
+ | `SIMPLE` | Identical content to PRETTY but without the decorative lines |
259
+ | `ONELINE` | Everything on one line separated by `\|` — suited for quick debugging |
260
+ | `LOG` | `key=value` format for log parsers (Datadog, Splunk, ...) |
261
+
262
+ ### PRETTY (default)
263
+
264
+ ```
265
+ ═════════════════════════════════════════════════════════════════
266
+ ⚠️ VALIDATION ERROR: parameter age
267
+ ═════════════════════════════════════════════════════════════════
268
+ Expected: a positive integer
269
+ Got: -5 (int)
270
+ Problem: value is negative
271
+ File info: File: main.py | Line: 42 | Path: ... | Function: validate
272
+ ─────────────────────────────────────────────────────────────────
273
+ 🔧 How to fix:
274
+ • Provide a value greater than 0.
275
+ ═════════════════════════════════════════════════════════════════
276
+ ```
277
+
278
+ ### SIMPLE
279
+
280
+ ```
281
+ ⚠️ VALIDATION ERROR: parameter age
282
+ Expected: a positive integer
283
+ Got: -5 (int)
284
+ Problem: value is negative
285
+ File info: File: main.py | Line: 42 | Path: ... | Function: validate
286
+ 🔧 How to fix:
287
+ • Provide a value greater than 0.
288
+ ```
289
+
290
+ ### ONELINE
291
+
292
+ ```
293
+ ⚠️ VALIDATION ERROR | parameter age | Expected: a positive integer | Got: -5 (int) | Problem: value is negative | File: main.py | Line: 42
294
+ ```
295
+
296
+ ### LOG
297
+
298
+ ```
299
+ error=VALIDATION ERROR value_label='parameter age' expected='a positive integer' value='-5 (int)' problem='value is negative' file='main.py' line=42
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Global settings
305
+
306
+ `SimpleExceptionSettings` is the central configuration for the entire
307
+ ecosystem. Changes apply to all exceptions in the project — no need to
308
+ override anything on individual classes:
309
+
310
+ ```python
311
+ from simple_exception import SimpleExceptionSettings, LOG
312
+
313
+ # Change the output mode — for example in production
314
+ SimpleExceptionSettings.DEFAULT_MESSAGE_MODE = LOG
315
+
316
+ # Disable location reporting
317
+ SimpleExceptionSettings.DEFAULT_GET_LOCATION = False
318
+
319
+ # Skip your own files when resolving the call location
320
+ # — useful if you have helper validation functions you don't want to see in output
321
+ SimpleExceptionSettings.DEFAULT_LOCATION_BLACKLIST = ("my_validators.py",)
322
+
323
+ # Reset everything to factory defaults
324
+ SimpleExceptionSettings.reset()
325
+ ```
326
+
327
+ Settings are protected by internal validation — if you provide an invalid
328
+ value, you get a clear error message instead of a mysterious crash:
329
+
330
+ ```python
331
+ SimpleExceptionSettings.DEFAULT_GET_LOCATION = "enabled"
332
+ ```
333
+
334
+ ```
335
+ ═════════════════════════════════════════════════════════════════
336
+ ⚠️ SETTINGS ERROR: DEFAULT_GET_LOCATION
337
+ ═════════════════════════════════════════════════════════════════
338
+ Expected: int or bool (e.g. True, False, 1, 2)
339
+ Got: "enabled" (str)
340
+ Problem: value is neither an int nor a bool
341
+ ─────────────────────────────────────────────────────────────────
342
+ 🔧 How to fix:
343
+ • Pass True or False to enable or disable location reporting.
344
+ • Pass an int to set the stack depth (e.g. 1, 2).
345
+ ═════════════════════════════════════════════════════════════════
346
+ ```
347
+
348
+ ---
349
+
350
+ ## Custom mode
351
+
352
+ If none of the built-in modes suits your needs, you can create your own.
353
+ Simply inherit from `ModeBase` and implement one method:
354
+
355
+ ```python
356
+ from simple_exception import ModeBase, SimpleExceptionSettings
357
+ from simple_exception.core import SimpleExceptionData
358
+
359
+ class SlackMode(ModeBase):
360
+ """Output formatted for Slack notifications."""
361
+
362
+ def _full_outcome(self, data: SimpleExceptionData, caller_info: dict | None) -> str:
363
+ parts = [f":warning: *{data.error_name}*"]
364
+ if data.value_label:
365
+ parts.append(f"*Value:* {data.value_label}")
366
+ if data.problem:
367
+ parts.append(f"*Problem:* {data.problem}")
368
+ if data.how_to_fix:
369
+ parts.append("*How to fix:*\n" + "\n".join(f"• {tip}" for tip in data.how_to_fix))
370
+ return "\n".join(parts)
371
+
372
+ SLACK_MODE = SlackMode()
373
+ SimpleExceptionSettings.DEFAULT_MESSAGE_MODE = SLACK_MODE
374
+ ```
375
+
376
+ When creating a custom mode, you can define up to three output methods.
377
+ Only `_full_outcome` is required — `_empty_outcome` and `_message_outcome`
378
+ have sensible defaults and can be overridden only when needed.
379
+
380
+ All fields available via `data` are listed in the [Parameters](#parameters) section.
381
+ In addition, `ModeBase` provides three helper methods for formatting:
382
+
383
+ | Method | Description |
384
+ |-----------------------------------|----------------------------------------------------------|
385
+ | `_print_intro_line(data)` | Builds the opening line with `error_name` and `value_label` |
386
+ | `_print_value_with_type(data)` | Value with type — e.g. `"hello" (str)` |
387
+ | `_print_caller_info(caller_info)` | Formats the location as a string or dictionary |
388
+
389
+ ---
390
+
391
+ ## Serialisation
392
+
393
+ Every `SimpleException` instance can serialise its state — useful for logging,
394
+ transport, or storing error reports:
395
+
396
+ ```python
397
+ e = SimpleException(
398
+ value_label = "parameter age",
399
+ expected = "a positive integer",
400
+ value = -5,
401
+ problem = "value is negative",
402
+ )
403
+
404
+ e.to_dict() # public attributes as a dictionary — UNSET values omitted
405
+ e.to_json() # JSON string — same data, suited for transport
406
+ e.to_debug_dict() # complete state including internal values — for debugging
407
+ ```
408
+
409
+ ```python
410
+ e.to_dict()
411
+ # {
412
+ # "error_name": "ERROR",
413
+ # "value": -5,
414
+ # "value_label": "parameter age",
415
+ # "expected": "a positive integer",
416
+ # "problem": "value is negative",
417
+ # }
418
+ ```
419
+
420
+ ---
421
+
422
+ ## Utils
423
+
424
+ Alongside the exception itself, the library provides three utility tools that
425
+ are also available independently.
426
+
427
+ ### UNSET and UnsetType
428
+
429
+ A sentinel for distinguishing an unset value from an intentionally passed
430
+ `None`. Used throughout the library — but you can use it in your own code too
431
+ if you face the same problem. Evaluates as `False` in a boolean context:
432
+
433
+ ```python
434
+ from simple_exception import UNSET, UnsetType
435
+
436
+ def connect(host: str, timeout: int | UnsetType = UNSET):
437
+ if timeout is UNSET:
438
+ timeout = get_default_timeout() # not provided → use default
439
+ elif timeout is None:
440
+ timeout = 0 # None passed intentionally → no timeout
441
+
442
+ if not UNSET:
443
+ print("UNSET is falsy ✓") # True — bool(UNSET) == False
444
+ ```
445
+
446
+ ### bool_or_exception
447
+
448
+ A shortcut for the pattern where a function either returns `False` or raises
449
+ a `SimpleException`. Eliminates repetitive conditional code in places where
450
+ a `return_bool` parameter exists — a flag that controls whether to return
451
+ `False` on failure instead of raising:
452
+
453
+ ```python
454
+ from simple_exception.utils import bool_or_exception
455
+
456
+ def validate_age(age: int, return_bool: bool = False) -> bool:
457
+ if age <= 0:
458
+ return bool_or_exception(
459
+ return_bool,
460
+ value_label = "parameter age",
461
+ expected = "a positive integer",
462
+ value = age,
463
+ )
464
+ return True
465
+ ```
466
+
467
+ ### extract_caller_info
468
+
469
+ A diagnostic function that walks the call stack and returns information about
470
+ the first relevant frame — file, line number, function name, and full path.
471
+ The function never raises an exception — it returns `None` on failure. It is
472
+ completely independent of the rest of the library and can be used anywhere:
473
+
474
+ ```python
475
+ from simple_exception.utils import extract_caller_info
476
+
477
+ info = extract_caller_info()
478
+ # {
479
+ # "file": "main.py",
480
+ # "full_path": "/projects/app/main.py",
481
+ # "line": 42,
482
+ # "function": "validate",
483
+ # }
484
+ ```
485
+
486
+ ---
487
+
488
+ ## About the Simple ecosystem
489
+
490
+ `simple-exception` is the foundation of the **Simple ecosystem** — it gives
491
+ the ecosystem a voice, helping it communicate with the user in a clear and
492
+ human way: not just reporting what went wrong, but pointing towards a fix.
493
+
494
+ The Simple ecosystem is a collection of small, self-contained Python libraries.
495
+ Each one solves exactly one thing — but all of them share a common philosophy:
496
+
497
+ **Dyslexia-friendly** — minimise mental load. Atomise code into self-contained
498
+ units, name files after the logic they contain, write explanations that describe
499
+ *why* — not just *what*.
500
+
501
+ **Programmer's zen** — nothing should be missing and nothing should be
502
+ superfluous. The journey is the destination: code should be fully understood;
503
+ better to go slowly and correctly than quickly and with mistakes. The
504
+ crystallisation approach — not perfection on the first try, but gradual
505
+ refinement towards it.
506
+
507
+ **Defensive style** — anticipate all possible failure modes so that only safe
508
+ paths remain. Never raise unexpected errors; degrade gracefully.
509
+
510
+ **Minimalism** — find the path to the goal in as few steps as possible, but
511
+ leave nothing out. Each file has one responsibility.
512
+
513
+ **Code as craft** — code should be pleasant to look at and evoke a sense of
514
+ harmony. Treat code as a small work of art — like a carpenter carving a
515
+ sculpture. Optimise for the user: everything should make sense without having
516
+ to study the documentation at length.
517
+
518
+ These are aspirations — a sense of direction. And that is exactly what the
519
+ note about the journey becoming the destination is all about. 🙂
520
+
521
+ ---
522
+
523
+ *The library is covered by tests across all modules — unit tests and
524
+ integration tests alike. Tests are part of the repository and serve
525
+ as living documentation of the expected behaviour.*