fix: validate active project in firestore:locations command - #10881
Open
joehan wants to merge 2 commits into
Open
fix: validate active project in firestore:locations command#10881joehan wants to merge 2 commits into
joehan wants to merge 2 commits into
Conversation
### Description
Updates the `firestore:locations` command action to retrieve the active project ID via `needProjectId(options)`.
Previously, running `firestore:locations` without an active project would pass `options.project` (which is undefined/null) directly to `api.locations(options.project)`. This resulted in calling the GCP Firestore API with `/projects/null/locations` or `/projects/undefined/locations`.
By using `needProjectId(options)` at the top of the command action, we ensure that a clean user-facing validation error ("No currently active project...") is thrown immediately if no project is active, matching standard CLI patterns.
### Scenarios Tested
1. Tested running `firestore:locations` without an active project (expected behavior: clean "No currently active project..." error message instead of failing on backend API call).
2. Tested running `firestore:locations` with a valid active project (expected behavior: successfully fetches and lists the firestore locations).
### Sample Commands
- Running without a project:
`firebase firestore:locations`
- **Before:** Fails on backend call with 403 Permission Denied on project null.
- **After:**
```
Error: No currently active project.
To run this command, you need to specify a project. You have two options:
- Run this command with --project <alias_or_project_id>.
- Set an active project by running firebase use --add, then rerun this command.
To list all the Firebase projects to which you have access, run firebase projects:list.
To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases
```
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the firestore:locations command to retrieve the project ID using the needProjectId utility function instead of directly accessing options.project. This ensures that a valid project ID is present before attempting to fetch the Cloud Firestore locations. There are no review comments, and I have no feedback to provide.
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.
Description
Updates the
firestore:locationscommand action to retrieve the active project ID vianeedProjectId(options).Previously, running
firestore:locationswithout an active project would passoptions.project(which is undefined/null) directly toapi.locations(options.project). This resulted in calling the GCP Firestore API with/projects/null/locationsor/projects/undefined/locations.By using
needProjectId(options)at the top of the command action, we ensure that a clean user-facing validation error ("No currently active project...") is thrown immediately if no project is active, matching standard CLI patterns.Scenarios Tested
firestore:locationswithout an active project (expected behavior: clean "No currently active project..." error message instead of failing on backend API call).firestore:locationswith a valid active project (expected behavior: successfully fetches and lists the firestore locations).Sample Commands
firebase firestore:locations