Skip to content

Replace failable init? with throwing init across all Coders - #50

Merged
trasch merged 3 commits into
mainfrom
throw-errors-from-init
Aug 7, 2026
Merged

trasch merged 3 commits into
mainfrom
throw-errors-from-init

Conversation

@trasch

@trasch trasch commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Converts all failable init? convenience initializers on VectorTile to throwing init throws, surfacing typed errors instead of silently returning nil.

Changes

  • New VectorTileError enum — public error type with LocalizedError conformance for human-readable messages:
    • .invalidCoordinate(x:y:z:)
    • .coordinateOutOfBounds(x:y:z:maxBound:)
    • .fileReadFailed(url:reason:)
    • .parseFailed(format:reason:)
  • 17 failable inits → throwing across VectorTile.swift, VectorTile+MVT.swift, VectorTile+MLT.swift, VectorTile+GeoJSON.swift, VectorTile+GPX.swift, VectorTile+FIT.swift, VectorTile+Shapefile.swift
  • MLT decoding errors are no longer swallowed by try? — they propagate through VectorTileError.parseFailed
  • File I/O errors now propagate as VectorTileError.fileReadFailed instead of being caught and returning nil
  • TileFormat.loadTile() now returns non-optional VectorTile (errors propagate naturally)
  • CLI commands receive typed, human-readable errors instead of generic fallback messages

⚠️ Breaking Change

All callers of VectorTile(...) convenience initializers must now use try instead of optional binding (if let / guard let). The return type is now VectorTile (non-optional).

Test Results

All 250 tests pass.

BREAKING CHANGE: All VectorTile convenience initializers that previously
returned nil on failure now throw VectorTileError instead:

- VectorTile(x:y:z:) — throws .invalidCoordinate / .coordinateOutOfBounds
- VectorTile(mvtData:x:y:z:) — throws coordinate errors + .parseFailed
- VectorTile(mltData:x:y:z:) — throws coordinate errors + .parseFailed
  (MLTDecoderError is no longer silently swallowed by try?)
- VectorTile(geoJsonData:) — throws .parseFailed + coordinate errors
- VectorTile(gpxData:) — throws .parseFailed + coordinate errors
- VectorTile(fitData:) — throws .parseFailed + coordinate errors
- VectorTile(shapefile:) — throws .parseFailed + coordinate errors
- All contentsOf* URL-based inits — additionally throw .fileReadFailed

New public error type VectorTileError conforms to LocalizedError for
human-readable messages. CLI commands now receive typed errors instead
of generic 'Failed to parse the resource' fallbacks.
@trasch trasch self-assigned this Aug 7, 2026
@trasch trasch added the enhancement New feature or request label Aug 7, 2026
@trasch trasch changed the title Replace failable init? with throwing init across all Coders (BREAKING) Replace failable init? with throwing init across all Coders Aug 7, 2026
@trasch
trasch merged commit 0cf8739 into main Aug 7, 2026
1 check passed
@trasch
trasch deleted the throw-errors-from-init branch August 7, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant