MessageHandler
MessageHandler()
capture_exceptions(code)
Run code and capture any exceptions as error messages.
Exceptions with empty messages are not reported as error messages but still mark the handler as failed.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The function to run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if code ran without exceptions, False otherwise. |
error(message, file=None, position=None, position_end=None)
Report an error and mark current script as failed.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The error message.
TYPE:
|
file
|
The file where the error occurred.
TYPE:
|
position
|
The position in the file where the error occurred.
TYPE:
|
position_end
|
The end position in the file where the error occurred.
TYPE:
|
error_from_exception(exception, omit_empty=False)
Print message from exception.
If the exception is a FilePositionException, the file and position information will be used.
| PARAMETER | DESCRIPTION |
|---|---|
exception
|
The exception to print the message from.
TYPE:
|
omit_empty
|
Whether to omit messages with empty text. Handler will still be marked as failed.
TYPE:
|
fail()
Mark the message handler as failed.
has_failed()
Check if the message handler has failed (errors reported).
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the message handler has failed, False otherwise. |
info(message, file=None, position=None, position_end=None)
Print informational message using current script.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Informational message.
TYPE:
|
file
|
The file where the message occurred.
TYPE:
|
position
|
The position in the file where the message occurred.
TYPE:
|
position_end
|
The end position in the file where the message occurred.
TYPE:
|
is_ok()
Check if the message handler is ok (no errors reported).
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the message handler is ok, False otherwise. |
message(message, prefix=None, file=None, position=None, position_end=None, fail=False)
Print message using current script.
This method should be overridden by subclasses.
| PARAMETER | DESCRIPTION |
|---|---|
prefix
|
Prefix for the message.
TYPE:
|
message
|
Message to print.
TYPE:
|
file
|
The file where the message occurred.
TYPE:
|
position
|
The position in the file where the message occurred.
TYPE:
|
position_end
|
The end position in the file where the message occurred.
TYPE:
|
fail
|
Whether the message indicates a failure.
TYPE:
|
reset()
Reset the message handler to ok.
warning(message, file=None, position=None, position_end=None)
Print warning using current script.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Warning message.
TYPE:
|
file
|
The file where the warning occurred.
TYPE:
|
position
|
The position in the file where the warning occurred.
TYPE:
|
position_end
|
The end position in the file where the warning occurred.
TYPE:
|
current_message_handler(use_fallback=False)
Get the current message handler.
| RETURNS | DESCRIPTION |
|---|---|
MessageHandler
|
The current message handler. |
error(message, file=None, position=None, position_end=None)
Report an error and mark current message handler as failed.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The error message.
TYPE:
|
file
|
The file where the error occurred.
TYPE:
|
position
|
The position in the file where the error occurred.
TYPE:
|
position_end
|
The end position in the file where the error occurred.
TYPE:
|
error_from_exception(exception, omit_empty=False)
Print message from exception using current message handler.
If the exception is a FilePositionException, the file and position information will be used.
| PARAMETER | DESCRIPTION |
|---|---|
exception
|
The exception to print the message from.
TYPE:
|
omit_empty
|
Whether to omit messages with empty text. Handler will still be marked as failed.
TYPE:
|
info(message, file=None, position=None, position_end=None)
Print informational message using current message handler.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Informational message.
TYPE:
|
file
|
The file where the message occurred.
TYPE:
|
position
|
The position in the file where the message occurred.
TYPE:
|
position_end
|
The end position in the file where the message occurred.
TYPE:
|
message(message, prefix=None, file=None, position=None, position_end=None, fail=False)
Print message using current message handler.
If there is no current message handler, messages that mark a failure will raise a RuntimeError, others will be ignored.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Message to print.
TYPE:
|
prefix
|
Prefix for the message.
TYPE:
|
file
|
The file where the message occurred.
TYPE:
|
position
|
The position in the file where the message occurred.
TYPE:
|
position_end
|
The end position in the file where the message occurred.
TYPE:
|
fail
|
Whether the message indicates a failure.
TYPE:
|
pop_message_handler()
Pop the current message handler from the stack.
push_message_handler(handler)
Push a new message handler onto the stack.
| PARAMETER | DESCRIPTION |
|---|---|
handler
|
The message handler to push.
TYPE:
|
remove_message_handler(handler)
Remove a message handler from the stack.
| PARAMETER | DESCRIPTION |
|---|---|
handler
|
The message handler to remove.
TYPE:
|
warning(message, file=None, position=None, position_end=None)
Print warning using current message handler.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Warning message.
TYPE:
|
file
|
The file where the warning occurred.
TYPE:
|
position
|
The position in the file where the warning occurred.
TYPE:
|
position_end
|
The end position in the file where the warning occurred.
TYPE:
|