From ff0f7a87540117c3211be2255da9775772ddd91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sat, 1 Dec 2018 20:15:44 -0800 Subject: [ios, macos] Refined source removal errors Clarified and copyedited the descriptions of errors that are raised when attempting to remove a source from a style. Worded the changelog entry more generically because the same method in Swift throws an error instead of returning. A mismatch would occur if the identifier is used by a different source than the one being removed. An application could cause this error to occur by keeping a reference to an MGLSource after changing the style URL of an MGLMapView. Another way would be to remove a source from the style, add another source to the style with the same identifier, then attempt to re-remove the original source from the style. --- platform/darwin/resources/Base.lproj/Foundation.strings | 6 +++--- platform/darwin/src/MGLSource.mm | 17 ++++++++--------- platform/ios/CHANGELOG.md | 2 +- platform/macos/CHANGELOG.md | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/platform/darwin/resources/Base.lproj/Foundation.strings b/platform/darwin/resources/Base.lproj/Foundation.strings index 360e3c8562..f092bdab30 100644 --- a/platform/darwin/resources/Base.lproj/Foundation.strings +++ b/platform/darwin/resources/Base.lproj/Foundation.strings @@ -298,9 +298,9 @@ /* OpenStreetMap short name attribution */ "OSM_SHORT_NAME" = "OSM"; -/* User-friendly error description */ -"REMOVE_SRC_FAIL_IN_USE_FMT" = "Source '%@' is in use, cannot remove."; +/* User-friendly error description; first placeholder is the source’s identifier */ +"REMOVE_SRC_FAIL_IN_USE_FMT" = "The source “%@” can’t be removed while it is in use."; /* User-friendly error description */ -"REMOVE_SRC_FAIL_MISMATCH_FMT" = "Identifier '%1$@' does not match source identifier '%2$s'"; +"REMOVE_SRC_FAIL_MISMATCH_FMT" = "The source can’t be removed because its identifier, “%@”, belongs to a different source in this style."; diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm index 62d3cfa808..fd54627471 100644 --- a/platform/darwin/src/MGLSource.mm +++ b/platform/darwin/src/MGLSource.mm @@ -70,20 +70,19 @@ _pendingSource = std::move(removedSource); _mapView = nil; } else if (outError) { - NSString *format = NSLocalizedStringWithDefaultValue(@"REMOVE_SRC_FAIL_IN_USE_FMT", @"Foundation", nil, @"Source '%@' is in use, cannot remove.", @"User-friendly error description"); - NSString *localizedDescription = [NSString stringWithFormat:format, self.identifier]; + NSString *localizedDescription = [NSString stringWithFormat: + NSLocalizedStringWithDefaultValue(@"REMOVE_SRC_FAIL_IN_USE_FMT", @"Foundation", nil, @"The source “%@” can’t be removed while it is in use.", @"User-friendly error description; first placeholder is the source’s identifier"), + self.identifier]; *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSourceIsInUseCannotRemove userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }]; } - } - else if (outError) { - // Consider raising an exception here - NSString *format = NSLocalizedStringWithDefaultValue(@"REMOVE_SRC_FAIL_MISMATCH_FMT", @"Foundation", nil, @"Identifier '%@' does not match source identifier '%s'", @"User-friendly error description"); - NSString *localizedDescription = [NSString stringWithFormat:format, - self.identifier, - self.rawSource ? self.rawSource->getID().c_str() : "(null)"]; + } else if (outError) { + // TODO: Consider raising an exception here + NSString *localizedDescription = [NSString stringWithFormat: + NSLocalizedStringWithDefaultValue(@"REMOVE_SRC_FAIL_MISMATCH_FMT", @"Foundation", nil, @"The source can’t be removed because its identifier, “%@”, belongs to a different source in this style.", @"User-friendly error description"), + self.identifier]; *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSourceIdentifierMismatch diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 7303ae4dec..155d34a3a9 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -10,7 +10,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Styles and rendering * Fixed an issue where the `{prefix}` token in tile URL templates was evaluated incorrectly when requesting a source’s tiles. ([#13429](https://github.com/mapbox/mapbox-gl-native/pull/13429)) -* Added `-[MGLStyle removeSource:error:]` that returns a `BOOL` indicating success (and an optional `NSError` in case of failure). ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399)) +* Added an `-[MGLStyle removeSource:error:]` method that returns a descriptive error if the style fails to remove the source, whereas `-[MGLStyle removeSource:]` fails silently. ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399)) * Added support for setting `MGLCollisionBehaviorPre4_0` in `NSUserDefaults`. ([#13426](https://github.com/mapbox/mapbox-gl-native/pull/13426)) * Modified the behavior of the map view so that programmatic camera transitions can no longer be interrupted by user interaction when `MGLMapView.zoomEnabled`, `MGLMapView.rotateEnabled`, `MGLMapView.scrollEnabled`, and `MGLMapView.pitchEnabled` are set to false. ([#13362](https://github.com/mapbox/mapbox-gl-native/pull/13362)) diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 2fc3935078..1692609257 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -4,7 +4,7 @@ * `MGLMapSnapshotter` now follows "MGLIdeographicFontFamilyName" app setting to reduce font data usage while snapshotting CJK maps [#13427](https://github.com/mapbox/mapbox-gl-native/pull/13427) * Fixed an issue where the `{prefix}` token in tile URL templates was evaluated incorrectly when requesting a source’s tiles. ([#13429](https://github.com/mapbox/mapbox-gl-native/pull/13429)) -* Added `-[MGLStyle removeSource:error:]` that returns a `BOOL` indicating success (and an optional `NSError` in case of failure). ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399)) +* Added an `-[MGLStyle removeSource:error:]` method that returns a descriptive error if the style fails to remove the source, whereas `-[MGLStyle removeSource:]` fails silently. ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399)) * Added support for setting `MGLCollisionBehaviorPre4_0` in `NSUserDefaults`. ([#13426](https://github.com/mapbox/mapbox-gl-native/pull/13426)) * Added the `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` property. ([#13463](https://github.com/mapbox/mapbox-gl-native/pull/13463)) -- cgit v1.2.1