Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geocodeWithOptions:completionHandler: crash on features unwrap #106

Closed
friedbunny opened this issue May 3, 2017 · 7 comments
Closed

geocodeWithOptions:completionHandler: crash on features unwrap #106

friedbunny opened this issue May 3, 2017 · 7 comments
Labels

Comments

@friedbunny
Copy link
Contributor

geocodeWithOptions:completionHandler: in v0.6.1 can fail to force-unwrap the returned JSON feature collection — MBGeocoder.swift#L179.

Thread 0 Crashed:
0   SomeApp		0x00000001001bca14 function signature specialization <Arg[1] = Owned To Guaranteed> of SomeApp.Geocoder.(geocode (SomeApp.GeocodeOptions, completionHandler : ([SomeApp.GeocodedPlacemark]?, Swift.String?, __ObjC.NSError?) -> ()) -> __ObjC.URLSessionDataTask).(closure #1) (MBGeocoder.swift:179)
1   SomeApp		0x00000001001b8b54 SomeApp.Geocoder.(geocode (SomeApp.GeocodeOptions, completionHandler : ([SomeApp.GeocodedPlacemark]?, Swift.String?, __ObjC.NSError?) -> ()) -> __ObjC.URLSessionDataTask).(closure #1) (MBGeocoder.swift:0)
2   SomeApp		0x00000001001b9078 function signature specialization <Arg[1] = Value Promoted from Box> of SomeApp.Geocoder.((dataTaskWithURL in _5EEF66B4503CFF193FAFED8963214E26) (Foundation.URL, completionHandler : (protocol<>) -> (), errorHandler : (__ObjC.NSError) -> ()) -> __ObjC.URLSessionDataTask).(closure #1).(closure #2) (MBGeocoder.swift:252)
3   libdispatch.dylib	0x00000001914d21fc _dispatch_call_block_and_release + 20
...

/cc @1ec5

@friedbunny friedbunny added the bug label May 3, 2017
@1ec5
Copy link
Contributor

1ec5 commented May 4, 2017

@ingalls @mattficke, are there any situations where the Geocoding API would return a non-FeatureCollection or a FeatureCollection that lacks a features array? (There's an assertion that we're dealing with a FeatureCollection, but assertions don't run in Release builds.)

@ingalls
Copy link

ingalls commented May 4, 2017

@1ec5 Not a valid reason no - On no results we simply return something like

{
    "type": "FeatureCollection",
    "features": []
}

If you run into someplace where this is not the case I would love to see the URL that generated it.

@ingalls ingalls closed this as completed May 4, 2017
@ingalls ingalls reopened this May 4, 2017
@mattficke
Copy link

@1ec5 not sure if this is relevant here, but batch queries to the permanent endpoint return an array of FeatureCollections.

@1ec5
Copy link
Contributor

1ec5 commented May 5, 2017

batch queries to the permanent endpoint return an array of FeatureCollections

We do account for that difference in batchGeocode(_:completionHandler:).

I’ve tried a number of possibilities but was unable to get the normal Geocoding API to return something that Swift couldn’t parse as a feature collection. If we remove the force-cast here, we’d still have to produce an error since it would be invalid data coming back from the API. (Optionally casting could obscure the error and cause an issue that’s more difficult to debug later.)

@postmechanical
Copy link

@1ec5 We've pulled the code into our project manually, adjusted the code to avoid force-unwraps since we don't allow force-unwraps in our code base (except in rare cases), and invoke the completion blocks with a new "failed to parse json" error instead.

@1ec5
Copy link
Contributor

1ec5 commented May 5, 2017

That sounds like a good solution for this project. Please let us know if you continued to run into that error in the wild (with details about the request, if possible).

@1ec5
Copy link
Contributor

1ec5 commented Jan 18, 2018

The crash in #106 (comment) was fixed by the migration to Codable in #127: now a malformed GeoJSON response will cause the error handler to be invoked instead of crashing. Please open separate issues if you encounter another situation where this library crashes on malformed input.

@1ec5 1ec5 closed this as completed Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants