From 582686e030b660f218cb7091aaab3cafa103465d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 18 May 2022 10:36:10 +0300 Subject: Return errors when found or None otherwise This commit adds a number of functions that return the error object when an error is found, or `None` otherwise. It avoids the use of exceptions as control flow constructs. --- quality_control/errors.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'quality_control/errors.py') diff --git a/quality_control/errors.py b/quality_control/errors.py index 29a38f9..1eda646 100644 --- a/quality_control/errors.py +++ b/quality_control/errors.py @@ -1,5 +1,7 @@ """Hold exceptions for QC package""" +from collections import namedtuple + class InvalidCellValue(Exception): """Raised when a function encounters an invalid value""" @@ -22,3 +24,9 @@ class ParseError(Exception): """Raised if any of the above exceptions are raised""" def __init__(self, *args): super().__init__(*args) + +InvalidValue = namedtuple( + "InvalidValue", ("line_number", "column_number", "value", "message")) + +DuplicateHeading = namedtuple( + "InvalidValue", ("line_number", "heading", "columns","message")) -- cgit v1.2.3