Skip to content

MessageHandlerFile

MessageHandlerFile(file, default_file_prefix=None)

Bases: MessageHandler

A message handler that writes messages to a file.

PARAMETER DESCRIPTION
file

The file to write messages to.

TYPE: IO[str]

default_file_prefix

Default prefix for messages without file.

TYPE: str | None DEFAULT: None

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: Callable[[], None]

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: str

file

The file where the error occurred.

TYPE: str | None DEFAULT: None

position

The position in the file where the error occurred.

TYPE: Any DEFAULT: None

position_end

The end position in the file where the error occurred.

TYPE: Any DEFAULT: None

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: Exception

omit_empty

Whether to omit messages with empty text. Handler will still be marked as failed.

TYPE: bool DEFAULT: False

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: str

file

The file where the message occurred.

TYPE: str | None DEFAULT: None

position

The position in the file where the message occurred.

TYPE: Any DEFAULT: None

position_end

The end position in the file where the message occurred.

TYPE: Any DEFAULT: None

is_ok()

Check if the message handler is ok (no errors reported).

RETURNS DESCRIPTION
bool

True if the message handler is ok, False otherwise.

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: str

file

The file where the warning occurred.

TYPE: str | None DEFAULT: None

position

The position in the file where the warning occurred.

TYPE: Any DEFAULT: None

position_end

The end position in the file where the warning occurred.

TYPE: Any DEFAULT: None