Skip to content

Comments

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

Merged
mattsoulanille merged 3 commits intotensorflow:masterfrom
tharvik:forward-browser-files-errors
Apr 23, 2025
Merged

[tfjs-core] do not hang on invalid browser files#8517
mattsoulanille merged 3 commits intotensorflow:masterfrom
tharvik:forward-browser-files-errors

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
21 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