Skip to content

rdar://133742708 (JSONDecoder crashes whole app on invalid input instead of throwing Error) #1043

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

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

kperryua
Copy link
Contributor

These try! assertions were incorrect. They were focused on the fact that the type of the value in the input JSON was guaranteed to be a string, but with the on-demand parsing behavior, there is no longer any initial UTF-8 validation step, which means decoding the keys into String values could fail. This needs to actually throw an error instead of trapping. Fortunately, this is an (embarrassingly) easy change to make.

@kperryua
Copy link
Contributor Author

@swift-ci Please test

@kperryua kperryua requested a review from parkera November 12, 2024 20:11
@kperryua kperryua merged commit f12ec24 into swiftlang:main Nov 13, 2024
3 checks passed
@jhoughjr
Copy link

I'll share my xp is it might be relevant. I just spent 12 hours yesterday chasing a bug tangent to this issue.
Long long story short, somehow a non printable character got into a folder name in Xcode's UI I assume.
This unprintable in the filename is how I crashed due to those force unwraps.
What would have been nice, was if at the site of the error, where it lists the line, column and index of the error, if it could also list what file threw.

I have to assume if it has a line number and char index, it also has the name at the same scope.
In the meantime I'm looking at finding or making a utility to scan a repo for any unprintable.

Because JSONDecoder gave incomplete context it took far longer to identify why it crashed.
I think a catch block would allow the increased context I desire to manifest.

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.

3 participants