diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2018-12-01 20:15:44 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2018-12-04 22:29:39 -0800 |
commit | ff0f7a87540117c3211be2255da9775772ddd91d (patch) | |
tree | 835239774e787a576aef24fd25188e461781a34c /platform/darwin | |
parent | 794b851f02b98c5f1652edc141b1a6feb459d59b (diff) | |
download | qtlocation-mapboxgl-ff0f7a87540117c3211be2255da9775772ddd91d.tar.gz |
[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.
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/resources/Base.lproj/Foundation.strings | 6 | ||||
-rw-r--r-- | platform/darwin/src/MGLSource.mm | 17 |
2 files changed, 11 insertions, 12 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 |