Repository navigation
Pass std::exception_ptr in MapObserver::onDidFailLoadingMap - #8418
Conversation
|
@brunoabinader, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @1ec5 and @friedbunny to be potential reviewers. |
|
@1ec5 does the new entries in |
a1a141d to
a0f3e95
Compare
|
What do you think about using |
1ec5
left a comment
There was a problem hiding this comment.
This is a welcome improvement! I do agree with @jfirebaugh that passing an std::exception_ptr all the way through would be preferable. Would that means we’d have different subclasses of std::exception_ptr for each failure mode, or would everything be an std::runtime_error?
does the new entries in
MGLErrorCoderequires updatingCHANGELOG.md?
The new error types themselves probably aren’t noteworthy, but let’s add a blurb noting that we’ve made the error that’s passed into -[MGLMapViewDelegate mapViewDidFailLoadingMap:withError:] more informative. Thanks!
| errorCode = MGLErrorCodeLoadStyleFailed; | ||
| break; | ||
| } | ||
| error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:errorDescription ? @{ |
There was a problem hiding this comment.
You can declare error on this line; no need for a separate declaration statement.
| errorCode = MGLErrorCodeNotFound; | ||
| break; | ||
| case mbgl::MapObserver::ErrorType::LoadingStyle: | ||
| errorCode = MGLErrorCodeLoadStyleFailed; |
There was a problem hiding this comment.
Would either MGLErrorCodeBadServerResponse or MGLErrorCodeConnectionFailed describe this failure, or is MGLErrorCodeLoadStyleFailed a distinct case?
There was a problem hiding this comment.
I'd prefer for map loading failure to have its own error type. However, we're no longer distinctively separating these in three different error types because std::runtime_error only provides a string.
| break; | ||
| } | ||
| error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:errorDescription ? @{ | ||
| NSLocalizedDescriptionKey: errorDescription, |
There was a problem hiding this comment.
Thank you so much for this! 👍 It turns out the error user info dictionary is called that because its contents are often displayed to the user with a localized description and sometimes a recovery suggestion. Here are some suggestions for improvements, taking advantage of the error type and assuming message comes directly from an std::exception_ptr, as suggested in #8418 (comment):
ParseStyle:NSLocalizedDescriptionKey: “The map failed to load because the style is corrupted.”NSLocalizedFailureReasonErrorKey:@(message.c_str())
NotFound:NSLocalizedDescriptionKey: “The map failed to load because the style can’t be found or is incompatible.”NSLocalizedFailureReasonErrorKey:@(message.c_str())
LoadingStyle:NSLocalizedDescriptionKey:@(message.c_str())
For the localized descriptions, we can use the NSLocalizedStringWithDefaultValue() macro (as described here) to potentially localize the error message.
Let me know if you’d prefer that I make these changes myself.
There was a problem hiding this comment.
Would that means we’d have different subclasses of std::exception_ptr for each failure mode, or would everything be an std::runtime_error?
Good question - it seems we're using only plain std::runtime_error everywhere in GL native code, so I'd say let's keep the same pattern.
As explained above, we'll no longer be able to distinct between the three error types - however I don't think that would make much difference anyways - the error message is the most important debugging information we need.
There was a problem hiding this comment.
We do have a couple subclasses of mbgl::util::Exception meant to provide more distinguishable errors. Currently, the only subclasses appear to be SpriteImageException and MisuseException; could we add more subclasses for these error types?
There was a problem hiding this comment.
could we add more subclasses for these error types?
I don't have a strong opinion on this, though for this approach to work we'd need to deduct the exception type via catch - see the exception juggling in https://github.com/mapbox/mapbox-gl-native/blob/master/include/mbgl/util/string.hpp#L44-L51 - for all platform-specific codes that needed to handle this.
There was a problem hiding this comment.
For the iOS and macOS implementations, the catch statements would replace the existing switch statement. For other implementations that don't need to distinguish individual failure reasons, catching a runtime_error would be sufficient.
tobrun
left a comment
There was a problem hiding this comment.
Android 👍, added a comment to #8389 (comment) to take this new error handling in account.
03718de to
686fe16
Compare
686fe16 to
18d98b3
Compare
18d98b3 to
a0d8310
Compare
|
related: #7890 |
Forwards the
error type and messagestd::exception_ptrfrom style::Observer::onStyleError as well as non-style related errors.As per @1ec5 comments in #8398:
Fixes #8398.