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")
Our processing_functions.py has a lot of lines like this:
loculus/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py
Lines 1918 to 1923 in f091cc1
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,typeandmessage. 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
ProcessingResultthey should returnRawProcessingResult(datum=None,warnings=None,errors=None), then the caller adds the rest (input_fields,output_field,type) here:loculus/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py
Line 431 in f091cc1
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: