util¶
util
¶
ExceptionWrapper
¶
ExceptionWrapper(info: Info, original: Exception, *args, **kwargs)
Bases: Exception
Wrapper for exceptions that provides additional details for tracer created code.
This class helps provide better error messages by including source code context and proper line numbers from the original code being traced.
| PARAMETER | DESCRIPTION |
|---|---|
info
|
Tracer information containing context about where the exception occurred
TYPE:
|
original
|
The original exception being wrapped
TYPE:
|
*args, **kwargs
|
Additional arguments passed to the parent Exception class
|
set_info
¶
set_info(info: Info)
Updates the tracer information and recalculates line offsets.
| PARAMETER | DESCRIPTION |
|---|---|
info
|
New tracer information to use
TYPE:
|
__str__
¶
Generates a formatted traceback string with proper context.
| RETURNS | DESCRIPTION |
|---|---|
|
A string containing the formatted traceback with source code context |
indent
¶
Indents each line in the source list by a specified number of indentation levels.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
List of strings to indent
TYPE:
|
indent
|
Number of indentation levels to apply (default: 1)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
List of indented strings |
try_catch
¶
try_catch(source: List[str], exception_source: List[str] = ['raise\n'], else_source: List[str] = ['pass\n'], finally_source: List[str] = ['pass\n'])
Wraps source code in a try-except-else-finally block.
Args:
source: The code to be wrapped in the try block
exception_source: Code for the except block (default: ["raise
"]) else_source: Code for the else block (default: ["pass "]) finally_source: Code for the finally block (default: ["pass "])
Returns:
List of strings representing the complete try-catch block, properly indented
get_dependencies
¶
Extracts global dependencies used by a function.
| PARAMETER | DESCRIPTION |
|---|---|
fn
|
The function to analyze for dependencies
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Dictionary mapping names to their corresponding global objects used by the function |
wrap_exception
¶
wrap_exception(exception: Exception, info: Info)
Wraps an exception with additional context from the tracer.
This function either updates an existing ExceptionWrapper or creates a new dynamically-typed exception class that inherits from both the original exception type and ExceptionWrapper.
| PARAMETER | DESCRIPTION |
|---|---|
exception
|
The exception to wrap
TYPE:
|
info
|
Tracer information containing context about where the exception occurred
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
A wrapped exception with enhanced traceback information |