-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
process: doc-only deprecate non-string env value #18990
process: doc-only deprecate non-string env value #18990
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this is a good approach.
src/node.cc
Outdated
"DEP01XX").IsNothing()) | ||
return; | ||
env_nonstring_deprecation_warned = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this, I would expect it to become pretty helpful when trying to figure out actual ecosystem usage.
doc/api/process.md
Outdated
@@ -867,7 +871,8 @@ console.log(process.env.foo); | |||
``` | |||
|
|||
Assigning a property on `process.env` will implicitly convert the value | |||
to a string. | |||
to a string. **This behavior is deprecated.** Future versions of Node.js will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d replace will
→ may
– at least I, personally, don’t feel comfortable committing to this.
src/node.cc
Outdated
@@ -2628,6 +2633,17 @@ static void EnvGetter(Local<Name> property, | |||
static void EnvSetter(Local<Name> property, | |||
Local<Value> value, | |||
const PropertyCallbackInfo<Value>& info) { | |||
if (config_pending_deprecation && !env_nonstring_deprecation_warned && | |||
!value->IsString()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also allow numbers + booleans, here and in the doc? I don’t see anything wrong with the well-defined behaviour we get from them, plus at least in the case of numbers doing this is pretty common (I count 3 test files in our suite alone).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Very good work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few nits. Generally lgtm tho
doc/api/deprecations.md
Outdated
@@ -914,6 +914,16 @@ Type: Runtime | |||
|
|||
This was never a documented feature. | |||
|
|||
<a id="DEP01XX"></a> | |||
### DEP01XX: process.env string coercion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just DEP00XX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already at DEP0100 :)
(Unless you meant DEP0XXX…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I mean DEP00XX. The same tooling that looks for REPLACEME in the docs looks for that pattern also and will flag it on release if it's not set properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, in that case we should fix the tooling also…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, see nodejs/node-core-utils#193
doc/api/deprecations.md
Outdated
<a id="DEP01XX"></a> | ||
### DEP01XX: process.env string coercion | ||
|
||
Type: Documentation-only (supports [`--pending-deprecation`][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move the supports --pending-deprecation
to the description below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/node.cc
Outdated
// Set by EnvSetter when a warning is emitted for non-string assignment to | ||
// process.env, to prevent the same warning from being emitted multiple times | ||
// per process. | ||
bool env_nonstring_deprecation_warned = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than add more global state can this be a flag on Environment
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
Why is this marked tsc-agenda? |
Removing tsc-agenda from here as well. We can leave this to github, there seems an agreement that this is a less contentious way to fix the problem. |
6fbae02
to
1b49210
Compare
1b49210
to
dce66fe
Compare
dce66fe
to
e7af63b
Compare
I plan on landing this this week, either tomorrow or on Wednesday. Untagging tsc-review as many TSC members have already looked at this. (I'll fix the deprecations.md merge conflict during landing.) |
!value->IsString() && !value->IsNumber() && !value->IsBoolean()) { | ||
if (ProcessEmitDeprecationWarning( | ||
env, | ||
"Assigning any value other than a string, number, or boolean value " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I am not a native English speaker, but I believe this message can be presented better. Unfortunately, I am also not sure how to improve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the second "value" on landing. Hope that helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. That felt redundant to me, when I read that for the first time.
Also, does it sound better if we change the second part to, "If the value is not one of them, use the string representation of it."?
Landed in 5826fe4. |
PR-URL: #18990 Refs: #15089 Refs: #18158 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
This is a follow-up of #18990. A new deprecation id was assigned in it, but it was not reflected in code and test. PR-URL: #19209 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: nodejs#18990 Refs: nodejs#15089 Refs: nodejs#18158 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
This is a follow-up of nodejs#18990. A new deprecation id was assigned in it, but it was not reflected in code and test. PR-URL: nodejs#19209 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
This PR provides an alternative approach to #18158 by deprecating the problematic behavior of
process.env
when a non-string is assigned to a property. I would like this deprecation to become Runtime in Node.js v11.Refs: #15089
Refs: #18158
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
process