Skip to content

Stop hiding read failures on web - #2230

Merged
vicajilau merged 4 commits into
mainfrom
fix/web-silent-read-failures
Oct 5, 2026
Merged

vicajilau merged 4 commits into
mainfrom
fix/web-silent-read-failures

Conversation

@vicajilau

Copy link
Copy Markdown
Owner

Fixes #2229

Depends on #2228. This branch is stacked on top of it, so please merge #2228 first. The base will then move to main.

Problem

On web, errors while reading a picked file were swallowed:

  • _streamFromWebPath caught every error and ended the stream. A read that failed halfway through made readAsByteStream() complete normally, handing the app a truncated or empty file as if the read had succeeded.
  • fetchBytesFromWebPath caught every error and returned null, so readAsBytes() retried through xFile and the original error was lost.
  • fetchStreamFromWebPath returned an empty stream instead of null for paths that are not web URLs, so the xFile fallback was never used for them.

Changes

  • Both helpers now return null only for paths that are not blob: or data: URLs, and let read errors propagate. readAsBytes() throws the original error and readAsByteStream() emits it on the stream, matching the native platforms.
  • Add browser tests for reading blob: and data: URLs and for reading a revoked blob: URL. Against the previous code the stream error test fails, which confirms it covers the silent failure.
  • Add the entry to the unreleased file_picker_web 4.0.1 changelog. No public signatures change, so it ships as a patch.

Testing

flutter test --platform chrome passes in file_picker_web (16 tests) and flutter analyze is clean.

_streamFromWebPath caught every error and ended the stream, so a read that failed halfway through made readAsByteStream() complete normally with a truncated or empty file. fetchBytesFromWebPath also caught every error and returned null, which made readAsBytes() retry through xFile and lose the original error.

Both helpers now return null only for paths that are not blob: or data: URLs and let read errors propagate, so readAsBytes() throws and readAsByteStream() emits the error.

Fixes #2229
…-failures

# Conflicts:
#	packages/file_picker_web/CHANGELOG.md
The fetch helpers only receive the file URI, so they now take a non-nullable path and _isWebPath no longer needs a null check. Invalid data: URLs are handled without a null assertion, and the changelog entry is shortened.
Base automatically changed from fix/web-safari-input-detached to main October 5, 2026 13:33
@vicajilau
vicajilau merged commit 408a51c into main Oct 5, 2026
18 checks passed
@vicajilau
vicajilau deleted the fix/web-silent-read-failures branch October 5, 2026 14:17
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.

Web: readAsBytes() and readAsByteStream() hide read failures

2 participants