Skip to content

Commit ceb3dfd

Browse files
authored
[in_app_purchase_storekit] Handle translation of errors nested in dictionaries (#6277)
The native userInfo object can contain nested dictionaries. Previously this information was lost because `FIAObjectTranslator encodeNSErrorUserInfo` did not handle `NSDictionary`s. Fixes flutter/flutter#138407 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates [following repository CHANGELOG style]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
1 parent cc3f2a3 commit ceb3dfd

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.13+1
2+
3+
* Handle translation of errors nested in dictionaries.
4+
15
## 0.3.13
26

37
* Added new native tests for more complete test coverage.

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAObjectTranslator.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,11 @@ + (NSDictionary *)getMapFromNSError:(NSError *)error {
166166
return nil;
167167
}
168168

169-
NSMutableDictionary *userInfo = [NSMutableDictionary new];
170-
for (NSErrorUserInfoKey key in error.userInfo) {
171-
id value = error.userInfo[key];
172-
userInfo[key] = [FIAObjectTranslator encodeNSErrorUserInfo:value];
173-
}
174-
return @{@"code" : @(error.code), @"domain" : error.domain ?: @"", @"userInfo" : userInfo};
169+
return @{
170+
@"code" : @(error.code),
171+
@"domain" : error.domain ?: @"",
172+
@"userInfo" : [FIAObjectTranslator encodeNSErrorUserInfo:error.userInfo]
173+
};
175174
}
176175

177176
+ (id)encodeNSErrorUserInfo:(id)value {
@@ -189,6 +188,12 @@ + (id)encodeNSErrorUserInfo:(id)value {
189188
[errors addObject:[FIAObjectTranslator encodeNSErrorUserInfo:error]];
190189
}
191190
return errors;
191+
} else if ([value isKindOfClass:[NSDictionary class]]) {
192+
NSMutableDictionary *errors = [[NSMutableDictionary alloc] init];
193+
for (id key in value) {
194+
errors[key] = [FIAObjectTranslator encodeNSErrorUserInfo:value[key]];
195+
}
196+
return errors;
192197
} else {
193198
return [NSString
194199
stringWithFormat:

packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/TranslatorTests.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ - (void)testErrorWithMultipleUnderlyingErrors {
191191
XCTAssertEqualObjects(expectedMap, map);
192192
}
193193

194+
- (void)testErrorWithNestedUnderlyingError {
195+
NSError *underlyingError = [NSError errorWithDomain:SKErrorDomain code:2 userInfo:nil];
196+
NSError *mainError =
197+
[NSError errorWithDomain:SKErrorDomain
198+
code:3
199+
userInfo:@{@"nesting" : @{@"underlyingError" : underlyingError}}];
200+
NSDictionary *expectedMap = @{
201+
@"domain" : SKErrorDomain,
202+
@"code" : @3,
203+
@"userInfo" : @{
204+
@"nesting" : @{
205+
@"underlyingError" : @{@"domain" : SKErrorDomain, @"code" : @2, @"userInfo" : @{}},
206+
207+
}
208+
}
209+
};
210+
NSDictionary *map = [FIAObjectTranslator getMapFromNSError:mainError];
211+
XCTAssertEqualObjects(expectedMap, map);
212+
}
213+
194214
- (void)testErrorWithUnsupportedUserInfo {
195215
NSError *error = [NSError errorWithDomain:SKErrorDomain
196216
code:3

packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_storekit
22
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.3.13
5+
version: 0.3.13+1
66

77
environment:
88
sdk: ^3.2.3

0 commit comments

Comments
 (0)