Uh oh!
There was an error while loading. Please reload this page.
src: delete process.env values set to undefined - #18158
Conversation
40e3915 to
6c63403CompareThere was a problem hiding this comment.
Is it possible to use EnvDeleter() instead of duplicating the code?
targos
commented
Jan 15, 2018
@cjihrig Not sure how. Two things to consider:
I pushed a change to move the code to another function, PTAL. |
joyeecheung
commented
Jan 15, 2018
There was a problem hiding this comment.
Instead of this, would it be better to show that the property TEST doesn't exist anymore in process.env, like in the test? As it is, it may not convey the idea clearly (setting undefined and then undefined is printed).
There was a problem hiding this comment.
like this?
console.log('TEST'inprocess.env);// => falseThere was a problem hiding this comment.
Yes. That's better, right?
Before this commit, setting a property of process.env to undefined would set the value to the string "undefined". This changes the behavior to instead remove the value, working like the delete operator. Refs: nodejs#15089
f49e58d to
f88476aComparetargos
commented
Jan 23, 2018
TimothyGu
left a comment
There was a problem hiding this comment.
Even if this is semver-major, I still think this behavioral change is too significant to be done on process.env, especially when we previously documented to do the contrary. Plus, as #16961 demonstrated, we can never have a truly Correct environmental variable implementation with a string-based API. My opinion for this is, instead of adding exceptions to a previously internally consistent class, we should just leave process.env alone.
The current behavior is not without precedent either. The Web Storage API (better known as Local Storage and Session Storage) also cast undefined to string.
mcollina
commented
Jan 29, 2018
I'm adding this to the next TSC agenda. |
Fishrock123
commented
Jan 31, 2018
Setting What about other non-string values? Shouldn't this throw or something? What about |
jasnell
commented
Jan 31, 2018
I'm torn on this one because I really like the idea of deleting but setting to |
BridgeAR
commented
Feb 1, 2018
I agree with @TimothyGu and I am also -1 on this. |
mhdawson
commented
Feb 5, 2018
This was discussed at the last TSC meeting. We are going to invite Timothy to this week's meeting and then call for a vote. |
rvagg
commented
Feb 7, 2018
I like this, but without being able to attend to hear discussion I'll register an abstention for now unless it comes back for a vote. |
mhdawson
commented
Feb 7, 2018
Discussed in TSC meeting today. Still differing views, lets see if we can get Timothy at the next meeting before having a vote. |
cjihrig
commented
Feb 19, 2018
I'm pretty much in the same boat as @addaleax. I think it should have worked like this from the start. If this PR doesn't land, I wouldn't be too upset though. |
joyeecheung
commented
Feb 19, 2018
I don't feel strongly for this to land, although the comment in #18158 (comment) should be addressed
It feels even stranger if we treat null and undefined differently. |
Don't feel strongly that this should land at this point given the objections
gireeshpunathil
commented
Feb 20, 2018
+1, better late than never. It is fair for a end user to expect rather than because that is how normal objects behave: |
TimothyGu
commented
Feb 20, 2018
@gireeshpunathil Your argument is one with a slippery slope. What makes We should instead focus on creating a better API in general that allows us to tackle #16961, rather than retrofitting suboptimal designs onto an object that has wide-spread compatibility impact. |
gireeshpunathil
commented
Feb 20, 2018
nothing, I don't discriminate null vs. undefined in this case - isn't it straightforward to fix
Existence of other, larger problem to be solved need not be a consideration for solving a problem for which fix is easy, right?
generally agree, but again, issue reported in #16961 need not hinder this from progressing, and both of them are not exclusive IMO. |
gireeshpunathil
commented
Feb 20, 2018
@TimothyGu - on a second thought, I don't believe this will have a wide-spread compatibility impact. Can you explain potential implications of this change in the field? |
addaleax
commented
Feb 20, 2018
@TimothyGu I’m in the “not too sad if this doesn’t happen” bucket, but I’m going to point out that many people (esp. language beginners) think of missing properties and properties with an |
mcollina
commented
Feb 20, 2018
Are you proposing a new API to improve the situation? I'm not sure that will help. A lot of modules rely on I think we are not providing a good experience to anyone relying on Side note, I think we might even throw if you are setting an object. |
addaleax
commented
Feb 20, 2018
@mcollina A separate API is what is being suggested in #16961, although for a completely different reason. |
Fishrock123
commented
Feb 21, 2018
This is not true. I am not opposed to moving away from |
targos
commented
Feb 21, 2018
I can look into this. Don't know if this is actually possible because AFAIK process.env is not really an object but a sort of C++ proxy acting like one. |
Fishrock123
commented
Feb 21, 2018
Hmmm, well it's mostly just a preference, |
addaleax
commented
Feb 21, 2018
@Fishrock123 What would be stored in the actual environment in that case? |
Now that is something I can get behind, and I believe that is better than both this PR and the status quo. And in fact I think we can and should start with documentation-only deprecation of setting non-string to The compatibility impact is difficult to measure however. @ChALkeR ;)
I see what you are saying. However, I'd like to contend that this PR doesn't help with the general issue of making Even worse, I understand that a lot of Node.js developers come from other JavaScript-based platforms, like the browser world, where For that reason, I believe throwing an error when setting non-string to
That would be even odder given the current behavior and implementation of
The point is that the impact will for sure be non-zero. And this, coupled with other disadvantages I pointed out before, forms the body of my objection. |
mcollina
commented
Feb 23, 2018
I'm definitely 👍 on this approach. If you are setting |
TimothyGu
commented
Feb 25, 2018
I have proposed my approach to this issue in #18990. |
mcollina
commented
Feb 27, 2018
I think this can be closed in favor of #18990. |
targos
commented
Feb 27, 2018
No objection to closing from me. |
PR-URL: #18990 Refs: #15089 Refs: #18158 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
PR-URL: nodejs#18990 Refs: nodejs#15089 Refs: nodejs#18158 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Before this commit, setting a property of process.env to undefined
would set the value to the string "undefined". This changes the
behavior to instead remove the value, working like the delete operator.
Refs: #15089
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
process