Skip to content

Refactor error/warnings to be less verbose in code #6536

Description

@corneliusroemer

Our processing_functions.py has a lot of lines like this:

ProcessingAnnotation.from_fields(
input_fields,
[output_field],
AnnotationSourceType.METADATA,
message=f"Could not map '{tax_id}' to common name. Code {response.status_code}: {body.get('detail', '')}",
)

In the beginning we didn't know exactly where things were going but this has gotten out of hand now.

Whenever we want to add a warning/error we construct it with input_fields, output_field, type and message. In total it's done 50 times in that file.

It seems to be that only the message is the actual information, the rest is always the same.

I think we can make the code more readable by changing what processing functions return. Instead of ProcessingResult they should return RawProcessingResult(datum=None,warnings=None,errors=None), then the caller adds the rest (input_fields, output_field, type) here:

That reduces verbosity in actual processing functions a lot, all they have to return is RawProcessingResult(errors=["error message"]).

We can also have helpers to shorten it for the case of just error:

processing_error("Error message")

Metadata

Metadata

Labels

codesmellFor warnings/lints without immediate harm but to be fixed eventuallypreprocessingIssues related to the preprocessing component

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions