firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.01k stars 201 forks source link

Issue with Handling Blank Parameterized Variables in Firebase Functions SDK #1500

Closed BenJackGill closed 5 months ago

BenJackGill commented 6 months ago

Related issues

None

[REQUIRED] Version info

node: v18.17.0 firebase-functions: 4.5.0 firebase-tools: 13.0.1 firebase-admin: 12.0.0

[REQUIRED] Steps to reproduce

It is common practice to provide an .env.example file with empty variables to show what is required in the .env file:

MY_VARIABLE=

That .env.example file often gets copied and renamed for actual use, for example, to .env.PROJECT_ID, and variables are assigned a value:

MY_VARIABLE="foo"

Then for Firebase Functions we might have a parameterized variable definition that looks like this:

export const MY_VARIABLE = defineString("MY_VARIABLE");

When .env.PROJECT_ID contains a value (e.g. MY_VARIABLE="foo"), the deployment functions correctly.

However, if someone copies .env.example without adding a value to MY_VARIABLE (resulting in MY_VARIABLE= in .env.PROJECT_ID), the expected behavior would be for Firebase Functions deployment to prompt for this value because it is required by the parameterized configuration. But that does not happen.

Currently, the deployment proceeds without any prompt or error even though MY_VARIABLE is empty.

This can lead to deployments with incomplete or incorrect configurations, potentially causing runtime errors or unexpected behavior.

Were you able to successfully deploy your functions?

Yes I can successfully deploy (which is the problem here). I did not see any error messages.

google-oss-bot commented 6 months ago

I found a few problems with this issue:

Berlioz commented 5 months ago

The difficulty here is that other implementations of .env configuration files in Javascript-based projects seem to have settled on FOO= being a valid thing to have in your file. This includes both the default .env handler in Node.js, and the dotenv package that was popular for supporting .env files before Node added that feature. Erroring when we see an empty line in a .env file, or setting the value to null instead of "", would be very surprising behavior for people used to those other libraries.

I'm sorry that the current behavior is annoying you, but I think I have to call it working as intended.

BenJackGill commented 5 months ago

Fair enough :)