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

[in_app_purchase] Make sure unsupported userInfo doesn't crash App#5111

Merged
fluttergithubbot merged 2 commits intoflutter:mainfrom
Baseflow:issue/100458
Apr 4, 2022
Merged

[in_app_purchase] Make sure unsupported userInfo doesn't crash App#5111
fluttergithubbot merged 2 commits intoflutter:mainfrom
Baseflow:issue/100458

Conversation

@mvanbeusekom
Copy link
Copy Markdown
Contributor

Starting from iOS 15.4 the Store Kit framework sends back underlying errors as part of the [NSError userInfo] field. This results in a crash because the [FIAObjectTranslator getMapFromNSError] method doesn't know how to handle this.

This PR updates the [FIAObjectTranslator getMapFromNSError] method to add support for underlying errors and also catches future unsupported type in a way that doesn't immediately crash the consuming app and instead returns an error string that can be handled on the client side.

Resolves flutter/flutter#100458

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

}
}
userInfo[key] = errors;
} else {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You'll need to handle strings as well; that's what broke the existing test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I also included a check on NSNumber just in case (including matching unit test).

} else if ([value isKindOfClass:[NSArray class]]) {
NSMutableArray *errors = [[NSMutableArray alloc] init];
for (id error in value) {
if ([error isKindOfClass:[NSError class]]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than assume that an array must contain errors, we should extract the general conversion code (i.e., this if/else if/... sequency) to a helper and recursively call that helper on the elements of the array.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, a lot more robust indeed.

Copy link
Copy Markdown
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@stuartmorgan-g stuartmorgan-g added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 4, 2022
@fluttergithubbot fluttergithubbot merged commit df6da95 into flutter:main Apr 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 5, 2022
@mvanbeusekom mvanbeusekom deleted the issue/100458 branch May 25, 2022 16:58
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p: in_app_purchase platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS15.4 in_app_purchase got crash because of Unsupported value for standard codec

3 participants