Error handling
This module provides utilities to convert python exceptions from/to a generic serialized format, so that webservice client can handle them in a hierarchical and forward-compatible manner.
- class wacryptolib.error_handling.StatusSlugMapper(exception_classes, fallback_exception_class, exception_slugifier=<function slugify_exception_class>)
Bases:
object
High-level wrapper for converting exceptions from/to status slugs.
- static gather_exception_subclasses(parent_classes)
Browse the module's variables, and return all found exception classes which are subclasses of parent_classes (including these, if found in module).
- Parameters:
module -- python module object
parent_classes (
Sequence
) -- list of exception classes (or single exception class)
- Returns:
list of exception subclasses
- get_closest_exception_class_for_status_slugs(slugs)
Return the closest exception class targeted by the provided status slugs, with a fallback class if no matching ancestor is found at all.
- slugify_exception_class(exception_class, *args, **kwargs)
Use the exception slugifier provided in __init__() to turn an exception class into a qualified name.
- wacryptolib.error_handling.gather_exception_subclasses(module, parent_classes)
Browse the module's variables, and return all found exception classes which are subclasses of parent_classes (including these, if found in module).
- Parameters:
module -- python module object
parent_classes (
Sequence
) -- list of exception classes (or single exception class)
- Returns:
list of exception subclasses
- wacryptolib.error_handling.slugify_exception_class(exception_class, excluded_classes=(<class 'object'>, <class 'BaseException'>, <class 'Exception'>), qualified_name_extractor=<function _fully_qualified_name>)
Turn an exception class into a list of slugs which identifies it uniquely, from ancestor to descendant.
- Parameters:
exception_class -- exception class to slugify
excluded_classes -- list of parents classes so generic that they needn't be included in slugs
qualified_name_extractor -- callable which turns an exception class into its qualified name
- Returns:
list of strings
- wacryptolib.error_handling.construct_status_slug_mapper(exception_classes, fallback_exception_class, exception_slugifier=<function slugify_exception_class>)
Construct and return a tree where branches are qualified slugs, and each leaf is an exception class corresponding to the path leading to it.
Intermediate branches can carry an (ancestor) exception class too, but only if this one is explicitely included in exception_classes.
The fallback exception class is stored at the root of the tree under the "" key.
- wacryptolib.error_handling.get_closest_exception_class_for_status_slugs(slugs, mapper_tree)
Return the exception class targeted by the provided status slugs, or the closest ancestor class if the exact exception class is not in the mapper.
If slugs is empty, or if no ancestor is found, the fallback exception of the mapper is returned instead.
- Parameters:
slugs -- qualified status slugs
mapper_tree -- mapper tree constructed from selected exceptions
- Returns:
exception class object