iOS: reject instead of crashing when an upload's file is missing - #48
Merged
Merged
Conversation
A background URLSession raises an NSInvalidArgumentException, not an error, when uploadTask(with:fromFile:) cannot read the file. Swift cannot catch it, so a file deleted between the caller's existence check and the task creation ended the app. An Objective-C helper now catches the exception. startUpload rejects, including the concurrent same-id calls parked on the first one. A chunked part that cannot be enqueued stalls with errorKind 'file'. Fixes DIANA-19VW. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dhruv-dangi-openspace
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a fix for the current version, not v10
On iOS,
uploadTask(with:fromFile:)on a background session throws an Objective-C exception when it cannot read the file. Swift cannot catch that exception, so the app dies. In Diana this is Sentry DIANA-19VW: about 2,500 crashes from 1,700 users since August. It usually happens at launch. The app checks that the file exists, and then a finished upload deletes that file before iOS opens it.This change wraps the call in a small Objective-C helper that catches the exception and returns it to Swift as an error.
Before: a missing file ends the app.
After:
startUploadrejects with "Cannot read file at …". Any concurrent calls with the same id get the same rejection. A chunked part that cannot be enqueued stalls witherrorKind: 'file'.What to look at
RNBGUCatchException.his now the one public header, so Swift can see it through the module umbrella. It imports only Foundation, so a plain Obj-C@import react_native_background_upload;still compiles.startUploadinRNBackgroundUpload.swift. Parked same-id calls now store both resolve and reject, so a failure reaches all of them.Decisions and trade-offs
startUploadresumes it.NSURLErrorCannotOpenFile, soerrorKind(for:)classifies it as'file'.Test Plan
yarn lint-root,yarn typecheckandyarn testpass with 37 tests.🤖 Generated with Claude Code