ctfsolver.error.manager_error¶
manager_error.py
Provides the ManagerError class for handling exceptions with colored output and optional verbose tracebacks.
- Classes:
ManagerError: Handles exceptions by printing colored error messages or full tracebacks, and provides a utility to wrap function execution with error handling.
- Usage:
Use ManagerError to manage error reporting in CLI applications, with support for verbose output and graceful handling of unexpected exceptions and keyboard interrupts.
Example
error_manager = ManagerError(verbose=True) error_manager.try_function(main_function)
Classes¶
Handles exceptions with colored output and optional verbose tracebacks for CLI applications. |
Module Contents¶
- class ManagerError(*args, **kwargs)[source]¶
Handles exceptions with colored output and optional verbose tracebacks for CLI applications.
This class provides methods to manage error reporting, including printing colored error messages, displaying full tracebacks when verbose mode is enabled, and gracefully handling unexpected exceptions and keyboard interrupts.
- verbose[source]¶
If True, displays full traceback on error; otherwise, shows a colored error message.
- Type:
- handle(exception
Exception, exit_code: int = 1): Handles an exception by printing a colored error message or full traceback, then exits with the given code.
- try_function(function
callable, *args, **kwargs): Executes a function, catching and handling exceptions and keyboard interrupts gracefully.
- handle(exception, exit_code=1)[source]¶
Handles exceptions by printing error information in color and exiting the program.
exception (Exception): The exception instance to handle. exit_code (int, optional): The exit code to use when exiting the program. Defaults to 1.
- Returns:
None
- Raises:
SystemExit – Exits the program with the specified exit code.
- Parameters:
- try_function(function, *args, **kwargs)[source]¶
Executes a given function with provided arguments, handling exceptions. :param function: The function to execute. :type function: callable :param *args: Variable length argument list to pass to the function. :param **kwargs: Arbitrary keyword arguments to pass to the function.
- Returns:
None
- Raises:
Handles all exceptions using the handle method. –
Prints a message if interrupted by the user (KeyboardInterrupt). –
- Parameters:
function (callable)