Skip to content

throw error when filter in --only target is invalid#10577

Open
aalej wants to merge 3 commits into
mainfrom
aalej_fix-6322
Open

throw error when filter in --only target is invalid#10577
aalej wants to merge 3 commits into
mainfrom
aalej_fix-6322

Conversation

@aalej
Copy link
Copy Markdown
Contributor

@aalej aalej commented May 29, 2026

Description

Fixes #6322. #6322 has 2 issues

  1. PowerShell parsing - fixed in handle powershell stripping commas #10288
  2. No errors or warnings are shown when running something like below. func2 is not a valid target since the expected format is functions:func2 (product:target)
firebase deploy --debug --only "functions:func1,func2"

Scenarios Tested

$ firebase deploy --only functions:helloWorld,helloWorld2

Error: "helloWorld2" is not a valid deploy target. Valid target prefixes are: database, storage, firestore, functions, hosting, remoteconfig, extensions, dataconnect, apphosting, auth

also verified that firebase deploy --only functions:helloWorld,functions:helloWorld2 deploys correctly

logs
$ firebase deploy --only functions:helloWorld,functions:helloWorld2

=== Deploying to 'PROJECT_ID'...

i  deploying functions
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8804

i  extensions: ensuring required API firebaseextensions.googleapis.com is enabled...
✔  extensions: required API firebaseextensions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged /Users/PATH/6322/functions (70.22 KB) for uploading
i  functions: ensuring required API run.googleapis.com is enabled...
i  functions: ensuring required API eventarc.googleapis.com is enabled...
i  functions: ensuring required API pubsub.googleapis.com is enabled...
i  functions: ensuring required API storage.googleapis.com is enabled...
✔  functions: required API eventarc.googleapis.com is enabled
✔  functions: required API run.googleapis.com is enabled
✔  functions: required API storage.googleapis.com is enabled
✔  functions: required API pubsub.googleapis.com is enabled
i  functions: generating the service identity for pubsub.googleapis.com...
i  functions: generating the service identity for eventarc.googleapis.com...
✔  functions: functions source uploaded successfully
i  functions: updating Node.js 24 (2nd Gen) function helloWorld(us-central1)...
i  functions: updating Node.js 24 (2nd Gen) function helloWorld2(us-central1)...
✔  functions[helloWorld(us-central1)] Successful update operation.
✔  functions[helloWorld2(us-central1)] Successful update operation.
Function URL (helloWorld(us-central1)): REDACTED
Function URL (helloWorld2(us-central1)): REDACTED

✔  Deploy complete!

Sample Commands

Notes

Is throwing an error too much? If so, we could instead opt for showing a warning message.

Copy link
Copy Markdown
Contributor

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

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 introduces validation for target filters in checkValidTargetFilters.ts to ensure that each target prefix is a valid deploy target, and adds a corresponding unit test. The review feedback highlights two important improvements: first, handling empty or whitespace-only targets in the validation loop to prevent confusing error messages, and second, avoiding the mutation of the shared SAMPLE_OPTIONS object in tests by using the object spread operator instead of Object.assign to prevent test pollution.

Comment thread src/checkValidTargetFilters.ts
Comment thread src/checkValidTargetFilters.spec.ts Outdated
Comment on lines +70 to +72
const options = Object.assign(SAMPLE_OPTIONS, {
only: "functions:func1,func2",
});
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.

medium

Using Object.assign(SAMPLE_OPTIONS, ...) mutates the shared SAMPLE_OPTIONS object, which can lead to test pollution and flaky tests if other tests rely on the default values of SAMPLE_OPTIONS.

Instead, use the object spread operator to create a shallow copy of SAMPLE_OPTIONS with the overridden properties.

    const options = {
      ...SAMPLE_OPTIONS,
      only: "functions:func1,func2",
    };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ya, this is a good catch.

Copy link
Copy Markdown
Member

@joehan joehan left a comment

Choose a reason for hiding this comment

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

LGTM once we add that spread operator

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.

Malformed deploy command from Windows Powershell is reported as successful deployment

3 participants