mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 20:41:15 +00:00
[AZ-359] Refactor C07: collapse RegionService catch ladder via RegionFailureClassifier
Replace 9 nearly-identical catch blocks in RegionService.ProcessRegionAsync with a single catch (Exception ex) that delegates to RegionFailureClassifier.Classify, returning a typed (category, errorMessage) pair. Preserves all original error messages stored in region summary files; failure-path call into HandleProcessingFailureAsync is unchanged. Net source delta: -38 lines in RegionService, +71 lines in new RegionFailureClassifier (pure static), +10 unit tests covering each category, precedence, status-code propagation, null guard. Tests: 68 unit (was 58) + 5 smoke + 3 stub-contract integration tests pass. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -36,7 +36,7 @@ Roadmap: `_docs/04_refactoring/03-code-quality-refactoring/analysis/refactoring_
|
||||
| AZ-356 | C05 | Stub endpoints return 501 | 1 | — | 2 | Done (In Testing) |
|
||||
| AZ-354 | C04 | Strict CORS by default | 1 | — | 2 | Done (In Testing) |
|
||||
| AZ-353 | C03 | Sanitize 5xx responses via IExceptionHandler | 1 | — | 3 | Done (In Testing) |
|
||||
| AZ-359 | C07 | Consolidate RegionService catch ladder | 2 | — | 3 | To Do |
|
||||
| AZ-359 | C07 | Consolidate RegionService catch ladder | 2 | — | 3 | Done (In Testing) |
|
||||
| AZ-357 | C06 | Drop tile Version concept; new migration | 2 | — | 5 | To Do |
|
||||
| AZ-362 | C09 | Idempotent POST contract | 2 | AZ-353 | 3 | To Do |
|
||||
| AZ-366 | C13 | Consolidate Haversine + filename parser | 3 | — | 2 | To Do |
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# Batch 09 Report — Refactor 03 Phase 2 (start)
|
||||
|
||||
Date: 2026-05-10
|
||||
Epic: AZ-350 (03-code-quality-refactoring)
|
||||
Status: ✅ Complete, pushed
|
||||
|
||||
## Scope (1 task / 3 SP)
|
||||
|
||||
| ID | C-ID | Title | Points | Component |
|
||||
|----|------|-------|--------|-----------|
|
||||
| AZ-359 | C07 | Consolidate 9-way catch ladder in `RegionService.ProcessRegionAsync` | 3 | Services.RegionProcessing |
|
||||
|
||||
Batch intentionally scoped to 1 task to (a) keep the turn manageable, (b) align with the K=3 cumulative review trigger that fires after batch 9.
|
||||
|
||||
## Changes
|
||||
|
||||
### Production
|
||||
- **NEW** `SatelliteProvider.Services.RegionProcessing/RegionFailureClassifier.cs`
|
||||
- `RegionFailureCategory` enum (Timeout, ExternalCancellation, TaskCanceledOther, OperationCanceledOther, RateLimit, Network, Unexpected)
|
||||
- `RegionFailureClassification` record (Category, ErrorMessage)
|
||||
- Static pure-function `Classify(ex, timeoutCts, externalCt)` — preserves all original error-message wording so downstream summary files do not change.
|
||||
- `internal` visibility; exposed to `SatelliteProvider.Tests` via `InternalsVisibleTo`.
|
||||
- **MODIFIED** `SatelliteProvider.Services.RegionProcessing/RegionService.cs`
|
||||
- Replaced 9 `catch` blocks (~50 LOC) with a single `catch (Exception ex)` (~10 LOC) that delegates to `RegionFailureClassifier.Classify` and logs a single structured warning with `category` and `errorMessage` properties. Failure-path call into `HandleProcessingFailureAsync` unchanged.
|
||||
- Net file delta: −38 lines.
|
||||
- **MODIFIED** `SatelliteProvider.Services.RegionProcessing.csproj`
|
||||
- Added `<InternalsVisibleTo Include="SatelliteProvider.Tests" />` for unit-test access.
|
||||
|
||||
### Tests
|
||||
- **NEW** `SatelliteProvider.Tests/RegionFailureClassifierTests.cs` (10 tests)
|
||||
- One per category (7) + precedence test (timeout > external cancel) + null-guard + status-code propagation in network case.
|
||||
- All ACs from `AZ-359_refactor_consolidate_region_catch_ladder.md` covered:
|
||||
- AC-1: each original case maps to the same human message — verified by string assertions on `ErrorMessage`.
|
||||
- AC-2: timeout precedence preserved — `Classify_TimeoutTakesPrecedenceOverExternalCancellation`.
|
||||
- AC-3: HTTP status code surfaced — `Classify_HttpRequestException_ReturnsNetwork_WithStatusCode`.
|
||||
- AC-4: unknown exception falls through to `Unexpected` — `Classify_UnknownException_ReturnsUnexpected`.
|
||||
|
||||
## Verification
|
||||
|
||||
- Unit tests: **68 passing** (was 58 → +10 new).
|
||||
- Integration suite: full Docker run (api + db + integration-tests) → all green, container exits 0.
|
||||
- API container builds clean → no compile errors in modified service.
|
||||
|
||||
## Behavior preservation
|
||||
|
||||
Observable failure path is identical:
|
||||
- Same error messages stored in `region.SummaryFilePath`.
|
||||
- Same `region.Status = "failed"` transition via `HandleProcessingFailureAsync`.
|
||||
- Same exception types caught (no new swallowing, no narrowed coverage).
|
||||
- Logging changes: 9 different log strings replaced with 1 structured log carrying `Category` as a property — net richer for log-aggregator queries while reducing source-level duplication.
|
||||
|
||||
## Commit
|
||||
|
||||
`[AZ-359] Refactor C07: collapse RegionService catch ladder via RegionFailureClassifier` — pushed to `dev`.
|
||||
|
||||
## Up next
|
||||
|
||||
- **Batch 10**: AZ-357 (drop tile Version + migration, 5 SP) — DB migration + DataAccess + TileService + tests.
|
||||
- **Batch 11**: AZ-362 (idempotent POST contract, 3 SP) — Api + RegionProcessing + RouteManagement.
|
||||
- **Cumulative review fires after this batch (K=3 trigger: batches 7, 8, 9 complete)** — should be the next non-implementation step.
|
||||
@@ -8,7 +8,7 @@ status: in_progress
|
||||
sub_step:
|
||||
phase: 4
|
||||
name: execution
|
||||
detail: "RUN_DIR=03-code-quality-refactoring; epic AZ-350; batches 7+8 done (Phase 1 complete: 6 tasks/12 SP); 21 tickets/~54 SP remaining; next batch 9 = AZ-359/357/362 (Phase 2 correctness, 11 SP)"
|
||||
detail: "RUN_DIR=03-code-quality-refactoring; epic AZ-350; batches 7+8+9 done (Phase 1 complete + AZ-359; 7 tasks/15 SP); 20 tickets/~51 SP remaining; cumulative review due (K=3 trigger fired); after review, next batch 10 = AZ-357 (drop tile Version + migration, 5 SP), then batch 11 = AZ-362 (idempotent POST, 3 SP)"
|
||||
retry_count: 0
|
||||
cycle: 1
|
||||
tracker: jira
|
||||
|
||||
Reference in New Issue
Block a user