Skip to content

[tfjs-core] do not hang on invalid browser files #8517

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

Conversation

tharvik
Copy link
Contributor

@tharvik tharvik commented Feb 15, 2025

tf.io.browserFiles doesn't fail when loading invalid files. or rather, it fails, but never rejects the promise, making the IOHandler.load hang forever.

wrapping the JSON.parse call in a try/catch and rejecting accordingly did the trick. and a small test to try it out.

note: FileReader.readAsText() is a callback way to go around reading files. the promise-based Blob.text() would make BrowserFile.load simpler and safer (but felt ouf-of-scope here).

Copy link
Member

@mattsoulanille mattsoulanille left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattsoulanille mattsoulanille enabled auto-merge (squash) April 23, 2025 18:55
@mattsoulanille mattsoulanille merged commit dc72617 into tensorflow:master Apr 23, 2025
1 check passed
@tharvik tharvik deleted the forward-browser-files-errors branch April 23, 2025 21:11
@tharvik tharvik mentioned this pull request May 16, 2025
20 tasks
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