-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid NODE_ENV message improvement #100
Comments
Hi @Rolandisimo, what would you suggest as an improved error message here? |
I'm running into the same issue. How can you specify valid choices for non-standard environments? As an example I need to tell it |
@cmbirk here you can see the default values for NODE_ENV https://github.com/af/envalid#envalidcleanenvenvironment-validators-options From the source code: // If validation for NODE_ENV isn't specified, use the default validation:
if (!varKeys.includes('NODE_ENV')) {
defaultNodeEnv = validateVar({
name: 'NODE_ENV',
spec: str({ choices: ['development', 'test', 'production'] }),
rawValue: env.NODE_ENV || 'production'
})
} Because in my project we have a // declarations.d.ts
declare type NODE_ENVIRONMENTS = "development" | "production" | "qa" | "test";
// env_variables.ts
NODE_ENV: str({
choices: ["qa", "production", "development", "test"] as NODE_ENVIRONMENTS[],
default: "development" as NODE_ENVIRONMENTS,
}), |
@af I wasn't sure about a good approach without refactoring the code too much. So, as an intermediate step I think it's not unreasonable to add a check for the specific What do you think? |
As of v7.0.0-beta.1, this library no longer ships a default NODE_ENV validator, so you can specify your own with whichever choices you wish. Here's a test case with an example: https://github.com/af/envalid/blob/master/tests/basics.test.ts#L138 This doesn't change the messaging of course, but if I understand correctly, if fixes the root issue here. If you think the error messages could use improvement still, please open up another PR or issue for that |
envalid/src/envalidWithoutDotenv.js
Line 34 in ad2f612
In my company we use
envalid
but with non-default environment values. Thus, I got my builds failing with the error above.Currently the function
validateVar
inenvalidWithoutDotenv.js
doesn't give a comprehensive error message with potential reasons for this issue and how to fix them. I had to actually go into the source code ofenvalid
to understand the reason why my builds are failing and how to fix it.My suggestion is to improve the error message and add guides for the user to understand how to fix this issue. Also, I suggest to add a part about
NODE_ENV
in the documentation that if it's not specified incleanEnv
then it takes the value ofdefaultNodeEnv
from the same file on line 56.I'd be more than glad to contribute.
The text was updated successfully, but these errors were encountered: