Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Pass std::exception_ptr in MapObserver::onDidFailLoadingMap #8418

Merged
merged 7 commits into from
Mar 17, 2017

Conversation

brunoabinader
Copy link
Member

@brunoabinader brunoabinader commented Mar 15, 2017

Forwards the error type and message std::exception_ptr from style::Observer::onStyleError as well as non-style related errors.

As per @1ec5 comments in #8398:

This would allow all the SDKs – not only the iOS and macOS SDKs – to provide more information when the map fails to load for some reason.

Fixes #8398.

@brunoabinader brunoabinader added Core The cross-platform C++ core, aka mbgl feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS Node.js node-mapbox-gl-native Qt Mapbox Maps SDK for Qt, aka Qt Location Mapbox GL labels Mar 15, 2017
@brunoabinader brunoabinader self-assigned this Mar 15, 2017
@mention-bot
Copy link

@brunoabinader, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @1ec5 and @friedbunny to be potential reviewers.

@brunoabinader
Copy link
Member Author

@1ec5 does the new entries in MGLErrorCode requires updating CHANGELOG.md?

@brunoabinader brunoabinader force-pushed the mapobserver-ondidfailloadingmap branch from a1a141d to a0f3e95 Compare March 15, 2017 14:53
Copy link
Contributor

@tmpsantos tmpsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qt looks good.

@jfirebaugh
Copy link
Contributor

What do you think about using std::exception_ptr as the error type rather than ErrorType + std::string? This would match our convention in other places, e.g. style::Observer::on{Glyphs,Sprite,Source,Tile,Resource}Error.

Copy link
Contributor

@1ec5 1ec5 left a 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 updating CHANGELOG.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 ? @{
Copy link
Contributor

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.

errorCode = MGLErrorCodeNotFound;
break;
case mbgl::MapObserver::ErrorType::LoadingStyle:
errorCode = MGLErrorCodeLoadStyleFailed;
Copy link
Contributor

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?

Copy link
Member Author

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.

break;
}
error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:errorDescription ? @{
NSLocalizedDescriptionKey: errorDescription,
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

@1ec5
Copy link
Contributor

1ec5 commented Mar 16, 2017

This fixes #8086, which I previously missed before filing #8398 as a duplicate.

Copy link
Member

@tobrun tobrun left a 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.

@brunoabinader brunoabinader force-pushed the mapobserver-ondidfailloadingmap branch 2 times, most recently from 03718de to 686fe16 Compare March 16, 2017 17:13
@brunoabinader brunoabinader changed the title Pass error type, message in MapObserver::onDidFailLoadingMap Pass std::exception_ptr in MapObserver::onDidFailLoadingMap Mar 16, 2017
@brunoabinader brunoabinader force-pushed the mapobserver-ondidfailloadingmap branch from 686fe16 to 18d98b3 Compare March 16, 2017 17:37
@brunoabinader brunoabinader force-pushed the mapobserver-ondidfailloadingmap branch from 18d98b3 to a0d8310 Compare March 17, 2017 08:58
@brunoabinader brunoabinader merged commit 6379cb0 into master Mar 17, 2017
@brunoabinader brunoabinader deleted the mapobserver-ondidfailloadingmap branch March 17, 2017 09:25
@kkaefer
Copy link
Member

kkaefer commented Mar 20, 2017

related: #7890

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS Node.js node-mapbox-gl-native Qt Mapbox Maps SDK for Qt, aka Qt Location Mapbox GL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants