Run extractor on a single file. Returns an ``ExtractionResult`` for all expected outcomes. Raises ``FatalExtractionError`` for both explicit fatal errors from the extractor and unexpected exceptions (wrapped with traceback logged).
(extractor: Extractor, gz_path: str)
| 114 | |
| 115 | |
| 116 | def _extract_one(extractor: Extractor, gz_path: str) -> ExtractionResult: |
| 117 | """Run extractor on a single file. |
| 118 | |
| 119 | Returns an ``ExtractionResult`` for all expected outcomes. Raises |
| 120 | ``FatalExtractionError`` for both explicit fatal errors from the |
| 121 | extractor and unexpected exceptions (wrapped with traceback logged). |
| 122 | """ |
| 123 | try: |
| 124 | return extractor.extract(gz_path) |
| 125 | # Order matters: FatalExtractionError and SkippedExtraction both inherit |
| 126 | # from ExtractionError, so they must be handled before the generic branch. |
| 127 | except FatalExtractionError: |
| 128 | raise |
| 129 | except SkippedExtraction as e: |
| 130 | return ExtractionResult( |
| 131 | gz_path=gz_path, |
| 132 | outcome=ExtractionOutcome.SKIPPED, |
| 133 | stats=e.stats, |
| 134 | error=e.reason, |
| 135 | reason_class=e.reason_class, |
| 136 | ) |
| 137 | except ExtractionError as e: |
| 138 | return ExtractionResult( |
| 139 | gz_path=gz_path, |
| 140 | outcome=ExtractionOutcome.FAILED, |
| 141 | error=str(e), |
| 142 | reason_class=e.reason_class, |
| 143 | ) |
| 144 | except Exception as e: |
| 145 | logger.exception("fatal unexpected exception while extracting %s", gz_path) |
| 146 | raise FatalExtractionError(str(e)) from e |
| 147 | |
| 148 | |
| 149 | def run_sequential( |
no test coverage detected