Skip to content

Refactor processing functions to use RawProcessingResult for less verbose error/warning handling#6537

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-error-warnings-verbosity
Draft

Refactor processing functions to use RawProcessingResult for less verbose error/warning handling#6537
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-error-warnings-verbosity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

resolves #3857

processing_functions.py had ~50 instances of verbose ProcessingAnnotation.from_fields(input_fields, [output_field], AnnotationSourceType.METADATA, message=...) boilerplate. Processing functions don't need to know about annotation structure—only the message matters. The caller (call_function) already has all the context to build the full annotation.

Changes

  • datatypes.py: Added RawProcessingResult(datum, warnings: list[str], errors: list[str]) and helpers processing_error(msg) / processing_warning(msg, datum)
  • processing_functions.py:
    • call_function now accepts both ProcessingResult and RawProcessingResult, converting the latter by attaching field/type metadata
    • All 13 processing functions converted to return RawProcessingResult
    • Helper functions (check_latin_characters, missing_taxonomy_service_error, taxonomy_network_error) simplified accordingly
    • Removed dead invalid_value_annotation function
    • 2208 → 1719 lines (−22%)
  • Tests: Updated assertions from .errors[0].message.errors[0] (now plain strings)

Before / After

# Before (6+ lines per error)
return ProcessingResult(
    datum=None, warnings=[],
    errors=[ProcessingAnnotation.from_fields(
        input_fields, [output_field], AnnotationSourceType.METADATA,
        message="Something went wrong.",
    )],
)

# After (1 line)
return processing_error("Something went wrong.")

Screenshot

N/A — backend refactoring only, no UI changes.

PR Checklist

  • All necessary documentation has been adapted.
  • The implemented feature is covered by appropriate, automated tests.
  • Any manual testing that has been done is documented (i.e. what exactly was tested?)
    • All 58 preprocessing unit tests pass (excluding test_nextclade_preprocessing.py which requires external nextclade3 binary).

…bose error/warning handling

- Add RawProcessingResult dataclass with plain string warnings/errors
- Add processing_error() and processing_warning() helper functions
- Modify call_function to handle both ProcessingResult and RawProcessingResult
- Convert all processing functions to return RawProcessingResult
- Simplify check_latin_characters and taxonomy helper functions
- Remove unused invalid_value_annotation function
- Update tests to match new return types (errors/warnings are now strings)

This reduces the file from 2208 to 1719 lines by eliminating repetitive
ProcessingAnnotation.from_fields(...) boilerplate in every error/warning.
Copilot AI changed the title [WIP] Refactor error/warnings to be less verbose in code Refactor processing functions to use RawProcessingResult for less verbose error/warning handling May 29, 2026
Copilot AI requested a review from corneliusroemer May 29, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor error/warnings to be less verbose in code Clearing date filters from the 'active filters' doesn't reset the filter input fields.

2 participants