Comments (6)
Hi @bram-rongen thanks for raising the issue. IIRC that change was intended as a bugfix, but I kind of see both sides with this one:
- node does distinguish between
''
andundefined
for env vars, so allowing an empty string without raising an error does make sense in a way, but... - I can't think of a case for having an empty string in an env var as a semantically useful value
Thoughts or feedback @SimenB @ibratoev ?
from envalid.
The intended functionality is to throw on missing values (undefined
), not falsey values (''
, null
, false
), so I think the current behavior is the correct one, and it was correct to have it in a patch release.
Whether the str
validator should throw or not on empty (or only whitespace) value, I have no opinion. Maybe?
from envalid.
After thinking about it some more, I think @SimenB is correct and the current behaviour is what we want. If you want to reject empty strings, it's pretty simple to create a custom string validator that works that way.
@bram-rongen I'd welcome that test if you'd still like to write it, otherwise I'll try and get around to it in the next few days.
from envalid.
Thanks for you response guys, for me the current behaviour works well enough! We've changed our test suite and all is well :)
from envalid.
There actually already was a test for this case :) I added a note in the readme, so hopefully that resolves the ambiguity moving forward.
from envalid.
Thinking about this, we might want to check for empty string... What I wanted to accomplish was to not throw MissingEnv
for false
passed programatically. I can see the error when something like this is done:
$ SOMETHING= node -pe 'process.env.SOMETHING.length'
0
But meh 😄
from envalid.
Related Issues (20)
- Help with Next.js HOT 5
- ts-expect-error problem with 7.2.1 HOT 4
- Make an optional case-insensitive flag HOT 2
- NPM package is not valid HOT 3
- Support `structuredClone` HOT 3
- How to access desc HOT 2
- Add parse options to str() HOT 1
- array validator HOT 1
- 7.3.0 breaking change? HOT 11
- Add option to load validator specs from .example.env file HOT 1
- Access value of env object by name HOT 1
- envalid in react-native for preview crashes without giving description of missing env HOT 2
- testOnly setting variable to Symbol instead of failing HOT 5
- Pick from validators HOT 2
- str({ devDefault: undefined }) generates an incorrect type HOT 2
- Require environment variables only if `NODE_ENV` is not set to `test` HOT 2
- Skipping env var validation in tests HOT 1
- Prevent process exit during tests HOT 1
- makeExactValidator is not exported HOT 1
- Combine envalid with Docker secrets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from envalid.