Skip to content

Quality cleanups: dedup Duration.seconds, statusCodeType placement, decouple composedURL error#323

Merged
3lvis merged 2 commits into
masterfrom
quality-leftovers
Jun 18, 2026
Merged

Quality cleanups: dedup Duration.seconds, statusCodeType placement, decouple composedURL error#323
3lvis merged 2 commits into
masterfrom
quality-leftovers

Conversation

@3lvis

@3lvis 3lvis commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Three of the four "review leftovers" from the cache-fixes review, in their own PR. Behavior-preserving — full suite (180) green, build warning-free.

1. Duration → seconds deduplicated

One extension Duration { var seconds } in Helpers.swift. Dropped the duplicate CacheExpiry.seconds(_:) static and the private copy in HTTPInterceptor.swift; CacheExpiry/CacheStore/RetryInterceptor all share it.

2. statusCodeType moved off the global Int namespace (breaking; v8)

public extension Int { var statusCodeType } polluted every consumer's Int. Replaced with Networking.StatusCodeType(statusCode:) — classification lives on the type it describes. Call sites + test updated; CHANGELOG noted under Changed/Removed.

3. composedURL/mapThrownError decoupled

composedURL threw an NSError that mapThrownError recognized by domain string. It now throws a typed NetworkingError.invalidRequest(.invalidURL), caught by the existing as? NetworkingError branch. The domain-string check remains only as a fallback for the rare other internal NSErrors, with an accurate comment.

Dropped: #4 (download-handler dedup)

Attempted to extract the shared skeleton of handleDataRequest/handleImageRequest into a performDownload wrapper, but passing the async work-closure (capturing cachingLevel/self) into an awaited call trips Swift 6.2's region isolation (sending … risks data races) — even though 6.3 accepts it. It was the least-valuable of the four (the two handlers differ in real ways: data caches before the status check, image success-only), so I reverted it rather than contort around the isolation checker. The two handlers stay as-is.

Tests

180 green, warning-free. Behavior-preserving refactors guarded by the existing suite; the one breaking change (#2) is exercised by the updated testStatusCodeType.

3lvis added 2 commits June 18, 2026 14:42
…wnload skeleton

Four review leftovers, all behavior-preserving (full suite green):

- Consolidate Duration→seconds into one extension (Helpers); drop the
  duplicate static on CacheExpiry and the private one in HTTPInterceptor.
- Move HTTP status classification off the global Int namespace: replace
  the public Int.statusCodeType extension with Networking.StatusCodeType
  (statusCode:), so consumers' Int isn't polluted. (Breaking; v8.)
- Decouple composedURL from mapThrownError: composedURL throws a typed
  NetworkingError.invalidRequest(.invalidURL) instead of an NSError the
  mapper had to recognize by domain string.
- Extract the shared download skeleton (request-id/clock/emit/catch/
  complete) into performDownload; handleDataRequest/handleImageRequest
  keep their type-specific branches, which differ in real ways (data
  caches pre-status-check, image success-only).

CHANGELOG updated for the two public-surface changes.
The performDownload wrapper passed an async work-closure capturing
cachingLevel/self into an awaited call, which Swift 6.2's region
isolation rejects (sending … risks data races) even though 6.3 accepts
it. It was the least-valuable of the four cleanups (the two handlers
differ in real ways), so restore them to their CI-green form, keeping
only the StatusCodeType(statusCode:) substitution. Fixes the other three
stand.
@3lvis 3lvis changed the title Quality cleanups: dedup, statusCodeType placement, error coupling, download skeleton Quality cleanups: dedup Duration.seconds, statusCodeType placement, decouple composedURL error Jun 18, 2026
@3lvis 3lvis marked this pull request as ready for review June 18, 2026 12:54
@3lvis 3lvis merged commit 82a605b into master Jun 18, 2026
1 check passed
@3lvis 3lvis deleted the quality-leftovers branch June 18, 2026 12:54
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.

1 participant