Skip to content

Commit

Permalink
feat/add-specific-error-info (#57)
Browse files Browse the repository at this point in the history
* Remove error msg on init

* Add sheet id to a1notation error msg

* Add .

* Specify the country of sheet title if unable to find document

* Add sheet_id constant

* Fix typo
  • Loading branch information
tohuynh committed Oct 15, 2023
1 parent 5594a45 commit c5e0147
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion siglatools/bin/load_spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def main():
raise InvalidWorkflowInputs(
ErrorInfo(
{
"reason": "Incorrect database enviroment specification. Use 'staging' or 'production'."
"reason": "Incorrect database environment specification. Use 'staging' or 'production'."
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion siglatools/bin/run_qa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def main():
raise InvalidWorkflowInputs(
ErrorInfo(
{
"reason": "Incorrect database enviroment specification. Use 'staging' or 'production'."
"reason": "Incorrect database environment specification. Use 'staging' or 'production'."
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion siglatools/bin/run_sigla_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def main():
raise InvalidWorkflowInputs(
ErrorInfo(
{
"reason": "Incorrect database enviroment specification. Use 'staging' or 'production'."
"reason": "Incorrect database environment specification. Use 'staging' or 'production'."
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion siglatools/databases/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

class UnableToFindDocument(BaseError):
def __init__(self, info: ErrorInfo):
super().__init__("Unable to find document in database", info)
super().__init__("Unable to find document in database.", info)
1 change: 1 addition & 0 deletions siglatools/databases/mongodb_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def _create_variable_reference(self, sheet_title: str, meta_data: Dict[str, str]
raise UnableToFindDocument(
ErrorInfo(
{
InstitutionField.country: meta_data.get(InstitutionField.country),
GoogleSheetsInfoField.sheet_title: sheet_title,
DatabaseField.collection: db_collection.variables,
DatabaseField.primary_keys: str(variable),
Expand Down
1 change: 1 addition & 0 deletions siglatools/institution_extracters/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ class MetaDataField:
class GoogleSheetsInfoField:
spreadsheet_title = "spreadsheet_title"
sheet_title = "sheet_title"
sheet_id = "sheet_id"
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ def raise_for_validity(self) -> None:
Raise an error if the a1 notation is invalid.
https://developers.google.com/sheets/api/guides/concepts#a1_notation
For a description of an A1 notation, please view the A1Notation class atttributes.
For a description of an A1 notation, please view the A1Notation class attributes.
"""

if int(self.start_row) > int(self.end_row):
# Start row is greater than end row
raise exceptions.InvalidRangeInA1Notation(
ErrorInfo(
{
GoogleSheetsInfoField.sheet_id: self.sheet_id,
GoogleSheetsInfoField.sheet_title: self.sheet_title,
MetaDataField.start_row: self.start_row,
MetaDataField.end_row: self.end_row,
Expand All @@ -240,6 +241,7 @@ def raise_for_validity(self) -> None:
raise exceptions.InvalidRangeInA1Notation(
ErrorInfo(
{
GoogleSheetsInfoField.sheet_id: self.sheet_id,
GoogleSheetsInfoField.sheet_title: self.sheet_title,
MetaDataField.start_column: self.start_column,
MetaDataField.end_column: self.end_column,
Expand All @@ -252,6 +254,7 @@ def raise_for_validity(self) -> None:
raise exceptions.InvalidRangeInA1Notation(
ErrorInfo(
{
GoogleSheetsInfoField.sheet_id: self.sheet_id,
GoogleSheetsInfoField.sheet_title: self.sheet_title,
MetaDataField.start_column: self.start_column,
MetaDataField.end_column: self.end_column,
Expand All @@ -263,6 +266,7 @@ def raise_for_validity(self) -> None:
raise exceptions.IncompleteColumnRangeInA1Notation(
ErrorInfo(
{
GoogleSheetsInfoField.sheet_id: self.sheet_id,
GoogleSheetsInfoField.sheet_title: self.sheet_title,
MetaDataField.start_column: self.start_column,
MetaDataField.end_column: self.end_column,
Expand Down
6 changes: 1 addition & 5 deletions siglatools/utils/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from typing import Union, Dict


Expand All @@ -19,12 +18,9 @@ def __init__(self, message: str, info: ErrorInfo):
super().__init__(message)
self.message = message
self.info = info
sys.stderr.write(
f"{self.__class__.__name__}: {self.message} {str(self.info)}\n"
)

def __str__(self):
return f"{self.message} {str(self.info)}"
return f"{self.__class__.__name__}: {self.message} {str(self.info)}"

def __reduce__(self):
return (self.__class__, self.message, self.info)
Expand Down

0 comments on commit c5e0147

Please sign in to comment.