mirar.errors package

Central module for handling errors during processing.

In general, the philosophy is that DataBatch objects should be processed, unless an error occurs.

If there is an error, then an ErrorReport should be created for the error.

These ErrorReport objects should be collated in a single ErrorStack object.

After processing is complete, the ErrorStack can then be used to summarise these errors, and track which images failed.

Ideally, it should be understood why the processing failed for a given image. Therefore the code distinguishes between internal errors which were deliberately raised, and external errors which were not deliberately raised.

In general, all internal errors should inherit from the mirar.errors.exceptions.BaseProcessorError class.

If the error is critical (i.e the image should not be processed further), then an error should be raised which inherits from the mirar.errors.exceptions.ProcessorError class.

If the error is non-critical (so processing should continue), then an error should be raised which inherits from the mirar.errors.exceptions.NoncriticalProcessingError class. In that case, processing will continue but the error will be logged.

Submodules

mirar.errors.error_report module

Module for ErrorReport objects.

An ErrorReport object summarises a single error raised by the code.

class mirar.errors.error_report.ErrorReport(error: Exception, processor_name: str, contents: list[str] | list[Path])[source]

Bases: object

Class representing a single error raised during processing

generate_full_traceback() str[source]

Returns a verbose string summarising the error

Returns:

String

generate_log_message() str[source]

Returns a human-readable string describing high-livel details about the error.

Returns:

String summary

get_error_line() str[source]

Returns only the critical error line raised by python

Returns:

string

get_error_message() str[source]

Returns the full error message raised by python

Returns:

String for single line

get_error_name() str[source]

Returns the name of the error

Returns:

Name

message_known_error() str[source]

Returns a human-readable string describing whether the error was an internal one intentionally raised by the code, or an unexpected external error

Returns:

String describing whether error was known

mirar.errors.error_stack module

Module for ErrorStack objects.

A ErrorStack object will contain a list of ErrorReport objects, and can correspond to

multiple errors raised by the code.

class mirar.errors.error_stack.ErrorStack(reports: list[ErrorReport] | None = None)[source]

Bases: object

Container class to hold multiple ErrorReport objects

add_report(report: ErrorReport)[source]

Adds a new ErrorReport

Parameters:

report – ErrorReport to add

Returns:

None

get_all_reports() list[ErrorReport][source]

Returns the full list of error reports (both critical and non-critical).

Returns:

list of ErrorReports

summarise_error_stack(output_path=None, verbose: bool = True) str[source]

Returns a string summary of all ErrorReports.

Parameters:
  • output_path – Path to write summary in .txt format (optional)

  • verbose – boolean whether to provide a verbose summary

Returns:

String summary of errors

mirar.errors.exceptions module

Module containing common exceptions or base exceptions for the code.

In general, all internal errors should inherit from the mirar.errors.exceptions.BaseProcessorError class.

If the error is critical (i.e the image should not be processed further), then an error should be raised which inherits from the mirar.errors.exceptions.ProcessorError class.

If the error is non-critical (so processing should continue), then an error should be raised which inherits from the mirar.errors.exceptions.NoncriticalProcessingError class. In that case, processing will continue but the error will be logged.

exception mirar.errors.exceptions.BaseProcessorError[source]

Bases: Exception

Base exception, from which all internal exceptions should derive

exception mirar.errors.exceptions.ImageNotFoundError[source]

Bases: ProcessorError, FileNotFoundError

Base class for all exceptions concerning missing images

exception mirar.errors.exceptions.NoncriticalProcessingError[source]

Bases: BaseProcessorError

Base class for all non-critical internal exceptions

exception mirar.errors.exceptions.ProcessorError[source]

Bases: BaseProcessorError

Base class for all critical internal exceptions