-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qt looks good.
What do you think about using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
MGLErrorCode
requires 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!
platform/ios/src/MGLMapView.mm
Outdated
errorCode = MGLErrorCodeLoadStyleFailed; | ||
break; | ||
} | ||
error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:errorDescription ? @{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can declare error
on this line; no need for a separate declaration statement.
platform/ios/src/MGLMapView.mm
Outdated
errorCode = MGLErrorCodeNotFound; | ||
break; | ||
case mbgl::MapObserver::ErrorType::LoadingStyle: | ||
errorCode = MGLErrorCodeLoadStyleFailed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would either MGLErrorCodeBadServerResponse
or MGLErrorCodeConnectionFailed
describe this failure, or is MGLErrorCodeLoadStyleFailed
a distinct case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
platform/ios/src/MGLMapView.mm
Outdated
break; | ||
} | ||
error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:errorDescription ? @{ | ||
NSLocalizedDescriptionKey: errorDescription, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_ptr
from style::Observer::onStyleError as well as non-style related errors.As per @1ec5 comments in #8398:
Fixes #8398.