Exceptions

Exception module

This module contains specialized Exception classes which allow for aggregation of all errors identified in a subject. These exceptions provide the structure to collect multiple exceptions at varying levels within a validation process, and display them in a meaningful way.

rumydata.exception.debug()

Exception debug mode control

A switch to control exception message sanitation. This is a static function which will always return False. In order to enable debug mode, you must monkey patch this function using the mock library. This is made to intentionally be inconvenient in order to prevent accidental disclosure of data in exception logs through overuse of the debug mode.

This method is used at runtime by the base _check method. In order to enable debugging, you must include a patch statement before calling a check. It is recommended that you do this with a context handler to ensure appropriate behavior of the patch.

example:

from unittest.mock import patch
from rumydata import field

with patch('rumydata.exception.debug', return_value=True):
    field.Integer(1).check_cell(None)
exception rumydata.exception.UrNotMyDataError(msg: str = None, errors: list = None)

Bases: Exception

Base exception class for rumydata package

This exception provides the structure for reporting nested exceptions in text format, in a way that the nested structure can be interpreted.

The constructor allows a list of errors to be associated with this exception, in addition to providing a way to override the default message printed when this exception is raised.

Parameters:
  • msg – a custom message to override the default with this exception is raised

  • errors – a list of UrNotMyDataError exceptions which are nested within this object.

exception rumydata.exception.CustomError(msg: str = None)

Bases: UrNotMyDataError

exception rumydata.exception.FileError(file, msg=None, errors: list = None)

Bases: UrNotMyDataError

File Error exception

Parameters:
  • file – name of the file reported with the error message.

  • msg – a custom message to use when reporting errors in the file.

  • errors – a list of errors contained in the file.

exception rumydata.exception.ColumnError(index: int, msg=None, errors: list = None, **kwargs)

Bases: UrNotMyDataError

Column Error Exception

Parameters:
  • msg – a custom message to use when reporting errors in the column.

  • errors – a list of errors contained in the column.

exception rumydata.exception.RowError(index: int, msg=None, errors: list = None, **kwargs)

Bases: UrNotMyDataError

Row Error exception

Parameters:
  • index – row number (using zero-indexing). Reported with the exception message to allow identification of the row.

  • msg – a custom message to use when reporting errors in this row.

  • errors – a list of errors contained in this row

  • zero_index – specify whether to use zero-indexing when reporting row number. If True, the index is reported as provided. If False, the index is increased by one.

exception rumydata.exception.CellError(index: int, msg=None, errors: list = None, use_excel_cell_format=False, **kwargs)

Bases: UrNotMyDataError

Cell Error exception

Parameters:
  • index – column number (using zero-indexing). Reported with the exception message to allow identification of the column.

  • msg – a custom message to use when reporting errors in this cell.

  • errors – a list of errors contained in this cell.

  • zero_index – specify whether to use zero-indexing when reporting column number. If True, the index is reported as provided. If False, the index increased by one.

exception rumydata.exception.PreProcessingError(msg: str = None, errors: list = None)

Bases: UrNotMyDataError

Data Preprocessing Exception

Thrown specifically when the data pre-processing step for a subject fails. This is treated differently than the exceptions thrown by all fields, since pre-processing exceptions prevent any further rules from being checked.