Errorloom
Base class for automatic error handling.
Classes inheriting from ErrorLoom will have all their methods automatically
wrapped in a try/except block. Caught exceptions are converted to BlueError
objects and passed to an error_handler method if one is defined on the instance.
To exempt a method from this behavior, use the @skip_error_loom decorator.
Source code in blue/errorloom.py
184 185 186 187 188 189 190 191 192 193 194 195 196 | |
Example - MyService
class MyService(ErrorLoom):
def do_work(self):
raise ValueError("Something went wrong")
def error_handler(self, error: BlueError, exception: Exception):
# Handle the error centrally
print(f"Caught error: {error}")
CatcherMeta
Bases: type
Metaclass that automatically wraps all methods of a class with error handling logic.
When a class uses CatcherMeta (or inherits from ErrorLoom), this metaclass:
- Iterates through all attributes defined in the class body.
- Identifies callable methods (excluding static/class methods).
- Wraps them with
_create_async_method_wrapperor_create_sync_method_wrapper. - Respects the
@skip_error_loomdecorator to bypass wrapping. - Checks base classes to see if a method was explicitly skipped in a higher class, preserving that exemption in the lower class.
Source code in blue/errorloom.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
__new__(mcs, name, bases, attrs)
Constructs the new class, intercepting and wrapping its methods.
Source code in blue/errorloom.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
Last update: 2026-02-04