Skip to content

Fix putFileResumable failing on a successful upload on Apple targets - #850

Open
anggrayudi wants to merge 1 commit into
GitLiveApp:masterfrom
anggrayudi:fix/722-putfileresumable-success
Open

Fix putFileResumable failing on a successful upload on Apple targets#850
anggrayudi wants to merge 1 commit into
GitLiveApp:masterfrom
anggrayudi:fix/722-putfileresumable-success

Conversation

@anggrayudi

Copy link
Copy Markdown

Fixes #722.

Problem

On Apple targets, putFileResumable closed its ProgressFlow with an exception when the upload succeeded:

ios.observeStatus(FIRStorageTaskStatusSuccess) { close(FirebaseStorageException(it!!.error().toString())) }

A success snapshot has no error, so it.error() is null and the collector received a FirebaseStorageException whose message was the string "null". That's exactly what @zacsst reported — an error on completion, and "if i swallow it, the file was successfully uploaded", because by then the upload really had finished.

Why this is unambiguous

putDataResumable sits 35 lines above in the same file and is otherwise identical to putFileResumable — same four observeStatus blocks, same awaitClose, same returned ProgressFlow. Its success handler is:

ios.observeStatus(FIRStorageTaskStatusSuccess) { close() }

So the correct code is already in the file; only putFileResumable got it wrong.

Android agrees on the intended semantics — its completion listener is close(it.exception), and it.exception is null on success, which is a normal close:

val onCompleteListener = OnCompleteListener<UploadTask.TaskSnapshot> { close(it.exception) }

Fix

One line: close the flow normally on success, matching putDataResumable and Android.

On testing

Two things worth being explicit about rather than glossing over.

I could not run the build or tests locally — Gradle dependency resolution stalls in my environment and I never got a green or red run, same as I noted on #847 and #848. Please treat CI as the real check.

No existing test could have caught this. commonTest has testPutDataResumable, which does ref.putDataResumable(data, metadata).collect {} — a collect that would throw if the flow closed exceptionally, so it is the right shape of test. But it exercises putDataResumable, the method that was already correct. There is no putFileResumable equivalent.

I didn't add one because it needs more than a copy-paste: File is platform-specific (File(NSURL) on Apple, File(Uri) on Android), and commonTest currently has no way to produce one — there's no File( usage in any test source. Doing it properly means an expect fun createTestFile(): File in test-utils with an actual per target that writes a temp file, which is a bigger change than this fix and one I'd rather not bundle in silently. Happy to do it as a follow-up if you'd like the coverage.

The Apple putFileResumable closed its ProgressFlow with a
FirebaseStorageException on FIRStorageTaskStatusSuccess, so a completed
upload surfaced to the collector as a failure. On success the snapshot has
no error, so the exception carried the message "null" and the only way to
use the API was to swallow it -- by which point the file had in fact
uploaded.

putDataResumable, 35 lines above and otherwise identical, already closes
normally on success, as does the Android implementation, whose
OnCompleteListener calls close(it.exception) with a null exception on
success. Match them.

Fixes GitLiveApp#722
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.

putFileResumable in iOS has possibly erroneous completion

1 participant