Skip to content

fix: validate active project in firestore:locations command - #10881

Open
joehan wants to merge 2 commits into
mainfrom
firestore-locations-need-project
Open

fix: validate active project in firestore:locations command#10881
joehan wants to merge 2 commits into
mainfrom
firestore-locations-need-project

Conversation

@joehan

@joehan joehan commented Jul 31, 2026

Copy link
Copy Markdown
Member

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
      

### 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
    ```

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@joehan
joehan requested a review from richieforeman July 31, 2026 22:40
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.

2 participants