Closed rainshen49 closed 2 months ago
Hello @rainshen49. Thanks for raising this issue. Can you elaborate on what you mean by a blank workspace? I assumed an empty directory but if I run flutterfire configure
in an empty directory, I get an expected error: FlutterAppRequiredException: The current directory does not appear to be a Flutter application project.
If you do suspect it's caused by a large number of projects, could you try running firebase projects:list
directly to see if the underlying Firebase CLI isn't the cause of this issue? You could also try flutterfire configure --verbose
to see if any additional logs are printed
@exaby73 thanks for the quick response. I should be more specific. By "blank" workspace, I mean the initial state after running something like "flutter create blank_workspace".
Running firebase projects:list
does not produce any errors.
...
5609 project(s) total.
Running flutterfire configure --verbose
doesn't give me anything more than the non-verbose version.
flutterfire configure --verbose
⠧ Fetching available Firebase projects...
type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast
I'd like to add that I've also tried flutterfire configure --yes --project=<my project id>
, but it still runs ⠏ Fetching available Firebase projects...
so arrives at the same error.
Could you check of firebase projects:list --json
has a null
value anywhere in the list? We currently assume we're getting perfect data from the CLI and some unchecked casting happens (see link below). I guess is it's throwing here but unfortunately, I cannot reproduce so you'll have to help me track this down :)
Hey @rainshen49 - it might be down to the size of the JSON response. From my very rough calculations, it could be around 60000 lines if you have 5609 firebase projects.
We've had an issue before for FFCLI when there is a large amount of projects to parse: https://github.com/invertase/flutterfire_cli/issues/150
I'll try to get a fix up 👍
@rainshen49 - do you mind cloning the flutterfire_cli project and testing this branch?
https://github.com/invertase/flutterfire_cli/tree/temp-file-for-large-json
To point your computer to the local version, run this command from the root of the project:
dart pub global activate --source="path" . --executable="flutterfire" --overwrite
In this branch, I've implemented a check to see whether the JSON response is large and used a temporary file to parse the data. I've also added logging which I hope will provide details on the problem.
When running FFCLI command, please add --debug
flag for console output. Example:
flutterfire configure --yes --project=PROJECT_ID --debug
If you were interested in adding any further logging in the local flutterfire_cli, you need to delete the snapshot at this directory:
flutterfire_cli/.dart_tool/pub/bin/flutterfire_cli_monorepo/*.snapshot
Then run this command again so you're using the latest local flutterfire_cli version:
dart pub global activate --source="path" . --executable="flutterfire" --overwrite
Let me know how it goes 🙏
@russellwheatley Thanks for the instruction, I was able to pinpoint where the null comes from. One of the projects has missing/empty resources
field. This causes https://github.com/invertase/flutterfire_cli/blob/add8df195e52a0ceee8bfbeb032205a30513e876/packages/flutterfire_cli/lib/src/firebase/firebase_project.dart#L61 to throw. This situation is possible if the project has none of the "default" resources configured, that is, if they haven't enabled Hosting, Storage, Realtime Database, or Firestore (which initializes locationId). These resources used to be enabled by default with a Firebase project, but is no longer the case as of some time last year.
My recommendation here is to just provide an empty value of FirebaseProjectResources because the app may still function if it uses other products. I'm not familiar with dart, but this worked for me
resources: FirebaseProjectResources.fromJson(
Map<String, dynamic>.from(
json['resources'] ?? <String, dynamic>{} as Map,
),
)
I have some additional comment/suggestions since I browsed this part of the code already.
firebase.getProjects
seems to be called twice in a row for no reason https://github.com/invertase/flutterfire_cli/blob/add8df195e52a0ceee8bfbeb032205a30513e876/packages/flutterfire_cli/lib/src/commands/config.dart#L421-L434 result
.where(
(Map<String, dynamic> e) =>
selectedProject == null ||
selectedProject == e['projectId'] ||
selectedProject == e['projectNumber'],
)
.map<FirebaseProject>((Map<String, dynamic> e)
This way, if any other project is malformed and would fail to parse, we're good as long as the user's chosen project is well-formed. This approach should also be faster when the number of projects is large.
@rainshen49 - ah, thanks for locating the bug and the additional getProjects()
. I'll be sure to get these fixed and updated in the next release 🙏
@russellwheatley Thanks! What's the usual release schedule?
@rainshen49 - typically when there is a bug fix or new feature being released. I'll aim to get this fixed and a release cut this week 👍
@rainshen49 - fix is in the latest dev release:
dart pub global activate flutterfire_cli 1.0.1-dev.3
Is there an existing issue for this?
CLI Version
1.0.0
Firebase Tools version
13.13.2
Flutter Doctor Output
Description
The CLI throws when running
flutterfire configure
on a blank workspace.Steps to reproduce
Run
flutterfire configure
Output:
Expected behavior
It should prompt me to pick a project.
Screenshots
No response
Additional context and comments
I have permission on a large number of internal projects. However, I'm unsure whether this is caused by too many projects to list because no additional debug info is available.