Repository navigation
Replace failable init? with throwing init across all Coders - #50
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts all failable
init?convenience initializers onVectorTileto throwinginit throws, surfacing typed errors instead of silently returningnil.Changes
VectorTileErrorenum — public error type withLocalizedErrorconformance for human-readable messages:.invalidCoordinate(x:y:z:).coordinateOutOfBounds(x:y:z:maxBound:).fileReadFailed(url:reason:).parseFailed(format:reason:)VectorTile.swift,VectorTile+MVT.swift,VectorTile+MLT.swift,VectorTile+GeoJSON.swift,VectorTile+GPX.swift,VectorTile+FIT.swift,VectorTile+Shapefile.swifttry?— they propagate throughVectorTileError.parseFailedVectorTileError.fileReadFailedinstead of being caught and returningnilTileFormat.loadTile()now returns non-optionalVectorTile(errors propagate naturally)All callers of
VectorTile(...)convenience initializers must now usetryinstead of optional binding (if let/guard let). The return type is nowVectorTile(non-optional).Test Results
All 250 tests pass.