Skip to content

Commit

Permalink
Better error message when on non-string values
Browse files Browse the repository at this point in the history
For augur curate titlecase
  • Loading branch information
j23414 committed Jul 14, 2023
1 parent ef00aa0 commit 72e6c95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion augur/curate/titlecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run(args, records):

titlecased_string = titlecase(record[field], articles, abbreviations)

failure_message = f"Failed to titlecase {field!r}:{record.get(field)!r} in record {record_id!r}"
failure_message = f"Failed to titlecase {field!r}:{record.get(field)!r} in record {record_id!r} because the value is a {type(record.get(field))!r} and is not a string."
if titlecased_string is None:
if failure_reporting is DataErrorMethod.ERROR_FIRST:
raise AugurError(failure_message)
Expand Down
9 changes: 8 additions & 1 deletion tests/functional/curate/cram/titlecase.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ Test case that fails on a non-string int

$ echo '{"bare_int": 2021}' \
> | ${AUGUR} curate titlecase --titlecase-fields "bare_int"
ERROR: Failed to titlecase 'bare_int':2021 in record 0
ERROR: Failed to titlecase 'bare_int':2021 in record 0 because the value is a <class 'int'> and is not a string.
[2]

Test case that fails on complext types (e.g. arrays)

$ echo '{"an_array": ["hello", "world"]}' \
> | ${AUGUR} curate titlecase --titlecase-fields "an_array"
ERROR: Failed to titlecase 'an_array':['hello', 'world'] in record 0 because the value is a <class 'list'> and is not a string.
[2]

Test cases when fields do not exist, decide if this should error out and may affect ingest pipelines
Expand Down

0 comments on commit 72e6c95

Please sign in to comment.