Refactor error/warnings to be less verbose in code
preprocessingcodesmell
Our processing_functions.py has a lot of lines like this: https://github.com/loculus-project/loculus/blob/f091cc10a7f48e55e70c2856d45450acf601d4d0/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py#L1918-L1923
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: https://github.com/loculus-project/loculus/blob/f091cc10a7f48e55e70c2856d45450acf601d4d0/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py#L431
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")
```
0 条评论