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

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 added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Feb 25, 2018
@TimothyGu TimothyGu requested review from mcollina, targos and a team February 25, 2018 21:51
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Feb 25, 2018
@TimothyGu TimothyGu added semver-major PRs that contain breaking changes and should be released in the next major version. process Issues and PRs related to the process subsystem. labels Feb 25, 2018
@TimothyGu
Copy link
Member Author

Copy link
Member

@addaleax addaleax left a 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;
}
Copy link
Member

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 makes sense to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

@mcollina mcollina left a 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.

Copy link
Member

@jasnell jasnell left a 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

@@ -914,6 +914,16 @@ Type: Runtime

This was never a documented feature.

<a id="DEP01XX"></a>
### DEP01XX: process.env string coercion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just DEP00XX

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<a id="DEP01XX"></a>
### DEP01XX: process.env string coercion

Type: Documentation-only (supports [`--pending-deprecation`][])
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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;
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@jasnell
Copy link
Member

jasnell commented Feb 26, 2018

Why is this marked tsc-agenda?

@TimothyGu
Copy link
Member Author

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

@mcollina
Copy link
Member

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 Issues and PRs to discuss during the meetings of the TSC. labels Feb 27, 2018
@TimothyGu TimothyGu force-pushed the doc-deprecate-process-env-non-string branch 2 times, most recently from 6fbae02 to 1b49210 Compare March 4, 2018 21:47
@TimothyGu
Copy link
Member Author

@addaleax and @jasnell: PTAL again

@TimothyGu TimothyGu force-pushed the doc-deprecate-process-env-non-string branch from 1b49210 to dce66fe Compare March 4, 2018 21:48
@TimothyGu TimothyGu force-pushed the doc-deprecate-process-env-non-string branch from dce66fe to e7af63b Compare March 4, 2018 21:52
@TimothyGu
Copy link
Member Author

@Trott Trott added the notable-change PRs with changes that should be highlighted in changelogs. label Mar 5, 2018
@TimothyGu TimothyGu added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed tsc-review labels Mar 6, 2018
@TimothyGu
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 "
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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

@TimothyGu
Copy link
Member Author

Landed in 5826fe4.

@TimothyGu TimothyGu closed this Mar 7, 2018
@TimothyGu TimothyGu deleted the doc-deprecate-process-env-non-string branch March 7, 2018 18:44
TimothyGu added a commit that referenced this pull request Mar 7, 2018
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]>
TimothyGu pushed a commit that referenced this pull request Mar 7, 2018
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]>
@tniessen tniessen added the deprecations Issues and PRs related to deprecations. label Apr 28, 2018
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
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]>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. deprecations Issues and PRs related to deprecations. notable-change PRs with changes that should be highlighted in changelogs. process Issues and PRs related to the process subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.