Storage Emulator Crash on Flutter iOS
[REQUIRED] Environment info
firebase-tools: 9.16.6
Platform: macOS
[REQUIRED] Test case
All emulators crash and exit when attempting to save a file on the storage emulator. In my case, I am attempting to upload a file to the emulator from an iOS simulator running a Flutter app. Uploading a file manually through the storage emulator UI works fine.
[REQUIRED] Steps to reproduce
- Start storage emulator
- Run the following code in a Flutter app:
await FirebaseStorage.instance.useStorageEmulator("localhost", 9199); ... await FirebaseStorage.instance.ref("attachments/dummy.jpeg").putFile(someFile);
[REQUIRED] Expected behavior
The file is uploaded to the storage emulator.
[REQUIRED] Actual behavior
Emulators shut down with the message "Error: An unexpected error has occurred."
The following error was found in the debug log file:
[debug] [2021-09-20T10:34:09.664Z] Error: ENOENT: no such file or directory, unlink '/var/folders/h3/mkvsvkv565dcwxpfgvxll0l00000gn/T/firebase/storage/blobs/00fdc6c6-770a-4ba7-b140-ecea748069eb_b_app_id.appspot.com_o_attachments%2F2DjvYL0eZM8U6ccXgTyC%2Fdummy.jpeg' at Object.unlinkSync (node:fs:1709:3) at Persistence.deleteFile (/usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/files.js:478:18) at StorageLayer.cancelUpload (/usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/files.js:152:27) at handleUpload (/usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:366:45) at /usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:443:24 at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5) at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5) at /usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:281:22 at param (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:354:14) at param (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:365:14) at param (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:365:14) at Function.process_params (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:410:3) at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:275:10) at /usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:89:9 [error] [error] Error: An unexpected error has occurred.
Also of note is that setting the line specifying which host and port the Flutter app should use, causes the following to be output to the app's debug output:
WARNING: Unable to set the Firebase Storage emulator settings. These must be set before any usages of Firebase Storage. If you see this log after a hot reload/restart you can safely ignore it.
This happens both when the app is hot reloaded and when it is not.
Hmm, interesting, might be an issue with the Flutter wrapper.
For info:
The flutter package I am using is firebase_storage: ^10.0.3.
I have tried this same code against a real Firebase project and it worked fine.
@abeisgoat Is there any update on this. It does make debugging anything to do with Storage on the emulator quite impossible for iOS.
Or would you recommend opening an issue on the Flutter wrapper repo perhaps?
I'll be tracking this issue as well, since I'm having the same problem.
File upload to firebase-storage emulator fails with the same kind of code shared above, getting all the same error or warning logs etc, only difference is it's not crashing/terminating all my firebase emulators, but instead I'm getting the following firebase-tools warning: "(node:83485) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.".
Also, after the "WARNING: Unable to set the Firebase Storage emulator settings." warning msg, I end up getting a "Unhandled Exception: [firebase_storage/unauthorized] User is not authorized to perform the desired action." error msg), even though I can confirm that my app user IS authenticated with firebase auth, and for the record, I do have the ootb storage.rules file in place and properly referenced in the firebase.json file. Those 2 previous warning+error flutter app log msgs are being thrown right after the FirebaseStorage.instance.ref("...").putFile(...) call.
Using flutter package firebase_storage: ^10.0.5
(+ flutter 2.5.2, firebase-tools 9.18.0, ios simulator iphone 13, vs code)
UPDATE: Found another ticket that is actually exactly explaining the error that I'm having and described right above, after I did some further testing under different conditions etc. Added a comment over there as well for more precision.. At this point, hard to tell if it's the same thing that you're having @ademanuele, of if yours is really different, but perhaps such below ticket will provide you with more info etc.
REF.: https://github.com/firebase/firebase-tools/issues/3584
UPDATE: Found another ticket that is actually exactly explaining the error that I'm having and described right above, after I did some further testing under different conditions etc. Added a comment over there as well for more precision.. At this point, hard to tell if it's the same thing that you're having @ademanuele, of if yours is really different, but perhaps such below ticket will provide you with more info etc.
REF.: #3584
I can confirm similar behavior to the linked issues is reproducible in Flutter firebase_storage: ^10.1.0 with iOS simulator.
I get the following error in the Flutter console.
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [firebase_storage/unauthorized] User is not authorized to perform the desired action.
======== Exception caught by Flutter framework =====================================================
The following FirebaseException was thrown While updating AsyncBuilder:
[firebase_storage/unauthorized] User is not authorized to perform the desired action.
And I get the following in the Firebase emulator console at the same time.
(node:983) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, unlink '/var/folders/0c/jrnzwy9n2z92z5k2s1pltcs00000gn/T/firebase/storage/blobs/16178e38-e70a-4f8d-a96e-d0ea783ad8b3_b_coach-panda.appspot.com_o_uploadedFiles%2Felectronic-card-transactions-october-2021-csv-1636540215026.zip'
at Object.unlinkSync (fs.js:1255:3)
at Persistence.deleteFile (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/firebase-tools/lib/emulator/storage/files.js:478:18)
at StorageLayer.cancelUpload (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/firebase-tools/lib/emulator/storage/files.js:152:27)
at handleUpload (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:366:45)
at /Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:443:24
at Layer.handle [as handle_request] (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/layer.js:95:5)
at /Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/index.js:281:22
at param (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/index.js:354:14)
at param (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/index.js:365:14)
at param (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/index.js:410:3)
at next (/Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/express/lib/router/index.js:275:10)
at /Users/nipuna/panda/products/coa_workspace/app/coa_backend/firebase_project/functions/node_modules/.pnpm/[email protected]/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:89:9
(node:983) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:983) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Hi folks, is there any updates with that? I have faced the same issue.
- iOS 14/15
- iOS firebase SDK 8.10.0
- firebase-tools 9.23.3
Hello guys, I'm facing the same issue, some solution?
Same issue here, any solutions so far?
I believe this issue is a duplicate of https://github.com/firebase/firebase-tools/issues/3550, which should be fixed by https://github.com/firebase/firebase-tools/pull/4210.