-
Notifications
You must be signed in to change notification settings - Fork 30k
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
util: make util.debuglog() consistent with doc #13841
Conversation
I am not sure if this is semver-major or semver-patch: this is more consistent with the doc but this may change some logging behavior, fixing any known errors in userland and surprising workarounds. |
lib/util.js
Outdated
@@ -151,7 +151,8 @@ exports.debuglog = function(set) { | |||
debugEnviron = process.env.NODE_DEBUG || ''; | |||
set = set.toUpperCase(); | |||
if (!debugs[set]) { | |||
if (new RegExp(`\\b${set}\\b`, 'i').test(debugEnviron)) { | |||
var sets = debugEnviron.split(',').map((s) => s.toUpperCase()); |
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.
Would it make more sense to do this on line 151?
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.
Is it OK it would be worthless to do all this if debugs[set]
is already 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.
Maybe we should place all the process.env.NODE_DEBUG
processing in the if
clause?
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.
The code on line 151, inside the debugEnviron === undefined
check, should only run once though, right? In the current position, it will run each time a new set is introduced.
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.
Oh, I did not notice it is used only in this function. So we can make it the array and use it instead of sets
, right?
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.
If you mean making debugEnviron
a Set
, then yes, that works for me.
test/sequential/test-util-debug.js
Outdated
env: Object.assign(process.env, { NODE_DEBUG: environ }) | ||
}); | ||
|
||
expectErr = expectErr.split('%PID%').join(child.pid); | ||
if (shouldWrite) { | ||
const SECTION = section.toUpperCase(); |
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.
Why the uppercase variable name?
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.
To differ from section
and to clarify the difference. What would you propose? Just reassign section
? Or name it like sectionUpperCase
?
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.
You could probably even get away with just using section.toUpperCase()
and child.pid
. They're only used to create an error message in a test.
@cjihrig Comments addressed. I have shortened the output data a bit to make test string more wrappable. New CI: https://ci.nodejs.org/job/node-test-pull-request/8774/ |
2 unstable results due to flaky |
So will we backport it or consider it semver-major? |
I have no idea how many people may be relying on the existing behavior. It also doesn't seem to be very high priority. I'd say semver major just to be safe, but I'm fine with either since it technically brings behavior closer to the documentation. |
I've set semver major for now, please, remove and backport if it will be reconsidered. |
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.
Code changes look fine but would you mind adding some detail to the commit message about how the code is closer aligned to the docs
Previous realization produces some false positive and false negative results due to: * conflicts between unescaped user input and RegExp special characters; * conflicts between parsing with `\b` RegExp symbol and non alphanumeric characters in section names. Fixes: #13728
@jasnell Hopefully done. |
Previous realization produces some false positive and false negative results due to: * conflicts between unescaped user input and RegExp special characters; * conflicts between parsing with `\b` RegExp symbol and non alphanumeric characters in section names. The doc does not mention any such restrictions. PR-URL: #13841 Fixes: #13728 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 3b0e800 |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
util
Fixes: #13728