★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/18990Nouvelle recherche | Portail wanayoo
Skip to content
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

Conversation

@TimothyGu
Copy link
Member

TimothyGu commented Feb 25, 2018

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

process

@TimothyGu TimothyGu requested review from mcollina, targos and nodejs/tsc Feb 25, 2018

@TimothyGu TimothyGu referenced this pull request Feb 25, 2018

Closed

src: delete process.env values set to undefined #18158

4 of 4 tasks complete
@TimothyGu

This comment has been minimized.

Copy link
Member Author

TimothyGu commented Feb 25, 2018

@addaleax
Copy link
Member

addaleax left a comment

Thanks! I think this is a good approach.

src/node.cc Outdated
"DEP01XX").IsNothing())
return;
env_nonstring_deprecation_warned = true;
}

This comment has been minimized.

@addaleax

addaleax Feb 25, 2018

Member

Thank you for this, I would expect it to become pretty helpful when trying to figure out actual ecosystem usage.

@@ -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

This comment has been minimized.

@addaleax

addaleax Feb 25, 2018

Member

I’d replace willmay – 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()) {

This comment has been minimized.

@addaleax

addaleax Feb 25, 2018

Member

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).

This comment has been minimized.

@TimothyGu

TimothyGu Feb 25, 2018

Author Member

👍 makes sense to me.

This comment has been minimized.

@targos
@mcollina
Copy link
Member

mcollina left a comment

LGTM.

Very good work.

@lpinca

lpinca approved these changes Feb 26, 2018

@jasnell
Copy link
Member

jasnell left a comment

Few nits. Generally lgtm tho

@@ -914,6 +914,16 @@ Type: Runtime
This was never a documented feature.
<a id="DEP01XX"></a>
### DEP01XX: process.env string coercion

This comment has been minimized.

@jasnell

jasnell Feb 26, 2018

Member

Just DEP00XX

This comment has been minimized.

@TimothyGu

TimothyGu Feb 27, 2018

Author Member

We are already at DEP0100 :)

(Unless you meant DEP0XXX…)

This comment has been minimized.

@jasnell

jasnell Feb 27, 2018

Member

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

This comment has been minimized.

@TimothyGu

TimothyGu Feb 27, 2018

Author Member

Ah, in that case we should fix the tooling also…

This comment has been minimized.

@gibfahn
<a id="DEP01XX"></a>
### DEP01XX: process.env string coercion
Type: Documentation-only (supports [`--pending-deprecation`][])

This comment has been minimized.

@jasnell

jasnell Feb 26, 2018

Member

I'd move the supports --pending-deprecation to the description below.

This comment has been minimized.

@addaleax

addaleax Feb 26, 2018

Member

@jasnell Just fyi, this was pretty recently added to the deprecation type on purpose in #18433

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;

This comment has been minimized.

@jasnell

jasnell Feb 26, 2018

Member

Rather than add more global state can this be a flag on Environment?

This comment has been minimized.

@TimothyGu

TimothyGu Feb 27, 2018

Author Member

Sure.

@jasnell

This comment has been minimized.

Copy link
Member

jasnell commented Feb 26, 2018

Why is this marked tsc-agenda?

@TimothyGu

This comment has been minimized.

Copy link
Member Author

TimothyGu commented Feb 26, 2018

@jasnell Because #18158 is also. If we were to take off the label we should do the same to that PR.

@mcollina

This comment has been minimized.

Copy link
Member

mcollina commented Feb 27, 2018

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.

@mcollina mcollina added tsc-review and removed tsc-agenda labels Feb 27, 2018

@TimothyGu TimothyGu force-pushed the TimothyGu:doc-deprecate-process-env-non-string branch 2 times, most recently from 6fbae02 to 1b49210 Mar 4, 2018

@TimothyGu

This comment has been minimized.

Copy link
Member Author

TimothyGu commented Mar 4, 2018

@addaleax and @jasnell: PTAL again

@TimothyGu TimothyGu force-pushed the TimothyGu:doc-deprecate-process-env-non-string branch from 1b49210 to dce66fe Mar 4, 2018

@TimothyGu TimothyGu force-pushed the TimothyGu:doc-deprecate-process-env-non-string branch from dce66fe to e7af63b Mar 4, 2018

@TimothyGu

This comment has been minimized.

Copy link
Member Author

TimothyGu commented Mar 4, 2018

@gibfahn

gibfahn approved these changes Mar 5, 2018

@targos

targos approved these changes Mar 5, 2018

@Trott Trott added the notable-change label Mar 5, 2018

@TimothyGu TimothyGu added author ready and removed tsc-review labels Mar 6, 2018

@TimothyGu

This comment has been minimized.

Copy link
Member Author

TimothyGu commented Mar 6, 2018

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 "

This comment has been minimized.

@thefourtheye

thefourtheye Mar 6, 2018

Contributor

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.

This comment has been minimized.

@TimothyGu

TimothyGu Mar 7, 2018

Author Member

I'll remove the second "value" on landing. Hope that helps.

This comment has been minimized.

@thefourtheye

thefourtheye Mar 7, 2018

Contributor

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."?

@TimothyGu

This comment has been minimized.

Copy link
Member Author

TimothyGu commented Mar 7, 2018

Landed in 5826fe4.

@TimothyGu TimothyGu closed this Mar 7, 2018

@TimothyGu TimothyGu deleted the TimothyGu:doc-deprecate-process-env-non-string branch Mar 7, 2018

TimothyGu added a commit that referenced this pull request Mar 7, 2018

process: doc-only deprecate non-string env value
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>

@thefourtheye thefourtheye referenced this pull request Mar 7, 2018

Closed

src: fix deprecation id for non-string env value #19209

2 of 2 tasks complete

TimothyGu added a commit that referenced this pull request Mar 7, 2018

src: fix deprecation id for non-string env value
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 <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>

MayaLekova added a commit to MayaLekova/node that referenced this pull request May 8, 2018

process: doc-only deprecate non-string env value
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>

MayaLekova added a commit to MayaLekova/node that referenced this pull request May 8, 2018

src: fix deprecation id for non-string env value
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 <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.