Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch JSON exceptions rather than crashing #856

Merged
merged 1 commit into from
Oct 23, 2020
Merged

Conversation

kstenerud
Copy link
Contributor

@kstenerud kstenerud commented Oct 22, 2020

Goal

We've previously made changes to wrap NSJSONSerialization to catch unexpected exceptions while encoding/decoding, but there is still an alternative path that hasn't been handled.

Design

Replicate the technique from BSGJSONSerialization in BSG_KSJSONCodec (wrap top-level APIs in try/catch blocks)

Changeset

BSG_KSJSONCodec has been modified such that the top-level APIs are guarded with try/catch blocks that log any errors.

Testing

Created a test app that exhausts memory in a region that uses the JSON serialization and observed the error messages prior to it crashing elsewhere from OOM.

@kstenerud kstenerud force-pushed the 5297-catch-json-errors branch from d2c304a to 24d6b09 Compare October 22, 2020 09:57
@kstenerud kstenerud changed the base branch from master to next October 22, 2020 09:57
@kstenerud kstenerud changed the title Catch JSON errors rather than crashing Catch JSON exceptions rather than crashing Oct 22, 2020
@kstenerud kstenerud force-pushed the 5297-catch-json-errors branch from 24d6b09 to 7fd3161 Compare October 22, 2020 10:00
@nickdowell
Copy link
Contributor

Is there a way to have automated test coverage of this?

@kstenerud
Copy link
Contributor Author

I'm not sure... So far the only exceptions I've managed are alloc exceptions during OOM situations. Other kinds of exceptions would require a bug in the codec.

@kstenerud kstenerud merged commit 8aa6ffb into next Oct 23, 2020
@kstenerud kstenerud deleted the 5297-catch-json-errors branch October 23, 2020 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants