You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Platform: Darwin bret-mbr.local 16.1.0 Darwin Kernel Version 16.1.0: Thu Oct 13 21:26:57 PDT 2016; root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64
Subsystem:
It would be handy if warnings provided a stack trace when thrown, so that I can track down the source of the warning and possibly PR upstream fixes. Right now, a lot of modules are throwing the missing new Buffer warning, but don't provide any hints at where to look to make the fix.
Yeah that would be handy I presume. I don't trace warnings very often so I wasn't aware of it. 😅 Still, is it possible to include a file and a line in the default warning message?
For example, this is pretty bad UX, and probably a common example of where people run into this issue:
bret-mbr:bret.io bret$ browserify src/index.js -o bundle.js --trace-warnings
(node:39223) DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.
There are two flags because --trace-deprecation was already there and already part of people's workflows. It didn't make sense to break that. --trace-warnings is more general to support all types of warnings, not just deprecations.
bret-mbr:test bret$ node glob.js --trace-warnings --trace-deprecation
TAP version 13
# Subtest: glob
1..6
(node:39743) DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.
ok 1 - should be equal
ok 2 - should be equal
ok 3 - should be equal
ok 4 - should be equal
ok 5 - should be equal
ok 6 - should be equal
ok 1 - glob # time=276.824ms
1..1
# time=299.257ms
And you only need one of the flags, not both. --trace-deprecations will show the stack trace only for DeprecationWarning. --trace-warnings will show the stack trace for all warning types.
so even passing the arg first doesn't work, for obvious reasons.
$ node --trace-warnings glob.js
TAP version 13
# Subtest: glob
1..6
(node:39800) DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.
ok 1 - should be equal
ok 2 - should be equal
ok 3 - should be equal
ok 4 - should be equal
ok 5 - should be equal
ok 6 - should be equal
ok 1 - glob # time=281.214ms
1..1
# time=306.824ms
Is there an ENV var I can use to pry into tooling problems like this? Could a more useful breadcrumb be provided in the default warning?
I think tap has a --node-arg=… option that you could use here?
Its using tape, but I'll look for a similar option.
Let me reframe the problem slightly:
Im using a common node tool (e.g. browserify but it could be whatever), that begins to throw a warning due to a new node release. I have a few free minutes and want to dig into the source of the warning. Whats the easiest way to trace the source of that warning?
I could be naive here, but it seems like there should be an easy and general way to solve this. Node args unfortunately aren't that general in situations like this. Env vars perhaps? Simply providing the path to the offending file in the default warning message (is that even possible)?
It might be hard. Its possible to walk the stack upwards, but knowing the first file/line that is "not node core" isn't necessarily easy. You can manually count, but if you are emitting the deprecation from code that can be reached by paths of different depths, its not pre-known how far up the stack the user code is.
I also feel the env var vs CLI option pain, there is no fix for this ATM. I am trying to make time to implement a NODEOPT env variable, so all (reasonable) CLI options can also be specified by env var, but for now, you'll need to use the CLI. For tape, you might be able to do node --trace-warnings $(which tape) ... or something of the like.
I dunno, how dissatisfied are you? Seems like its working as intended, but also slightly awkward. If more people hate it they will post bugs, and then someone might try and figure out a better way, but it does look like what you want is possible ATM, with the CLI arguments.
@sam-github Yes, working as intended, especially for library use. For node programs where passing the node argument passing is obfuscated, an ENV interface that you mentioned would improve the UX imo.
Is there an open issue or PR for that work I can reference here then close this one?
Activity
sam-github commentedon Nov 8, 2016
Isn't this exactly what https://nodejs.org/api/cli.html#cli_trace_warnings does?
bcomnes commentedon Nov 8, 2016
Yeah that would be handy I presume. I don't trace warnings very often so I wasn't aware of it. 😅 Still, is it possible to include a file and a line in the default warning message?
bcomnes commentedon Nov 8, 2016
For example, this is pretty bad UX, and probably a common example of where people run into this issue:
bnoordhuis commentedon Nov 8, 2016
@bcomnes
--trace-deprecation(As to why there are two flags: I don't know.)
jasnell commentedon Nov 8, 2016
There are two flags because
--trace-deprecationwas already there and already part of people's workflows. It didn't make sense to break that.--trace-warningsis more general to support all types of warnings, not just deprecations.bcomnes commentedon Nov 8, 2016
Still not working the way I would expect:
Heres running a browserify test:
Am I doing it wrong?
evanlucas commentedon Nov 8, 2016
try passing the flags before the file
jasnell commentedon Nov 8, 2016
For instance:
jasnell commentedon Nov 8, 2016
And you only need one of the flags, not both.
--trace-deprecationswill show the stack trace only forDeprecationWarning.--trace-warningswill show the stack trace for all warning types.bcomnes commentedon Nov 8, 2016
Aw sorry, the test was using child-process. I'm seriously not trying to be dense here 😬
https://github.com/substack/node-browserify/blob/master/test/glob.js
so even passing the arg first doesn't work, for obvious reasons.
Is there an ENV var I can use to pry into tooling problems like this? Could a more useful breadcrumb be provided in the default warning?
addaleax commentedon Nov 8, 2016
I think tap has a
--node-arg=…option that you could use here?bcomnes commentedon Nov 8, 2016
Its using tape, but I'll look for a similar option.
Let me reframe the problem slightly:
Im using a common node tool (e.g. browserify but it could be whatever), that begins to throw a warning due to a new node release. I have a few free minutes and want to dig into the source of the warning. Whats the easiest way to trace the source of that warning?
I could be naive here, but it seems like there should be an easy and general way to solve this. Node args unfortunately aren't that general in situations like this. Env vars perhaps? Simply providing the path to the offending file in the default warning message (is that even possible)?
sam-github commentedon Nov 8, 2016
It might be hard. Its possible to walk the stack upwards, but knowing the first file/line that is "not node core" isn't necessarily easy. You can manually count, but if you are emitting the deprecation from code that can be reached by paths of different depths, its not pre-known how far up the stack the user code is.
I also feel the env var vs CLI option pain, there is no fix for this ATM. I am trying to make time to implement a
NODEOPTenv variable, so all (reasonable) CLI options can also be specified by env var, but for now, you'll need to use the CLI. For tape, you might be able to donode --trace-warnings $(which tape) ...or something of the like.bcomnes commentedon Nov 8, 2016
A
NODEOPTalternative sounds like it might be general enough, and relatively easy to use. Happy to hear its in the works.The suggestions are also helpful to the random cases that I'm looking into thank you.
Should I close this, reference an existing issue, leave open?
sam-github commentedon Nov 9, 2016
I dunno, how dissatisfied are you? Seems like its working as intended, but also slightly awkward. If more people hate it they will post bugs, and then someone might try and figure out a better way, but it does look like what you want is possible ATM, with the CLI arguments.
bcomnes commentedon Nov 11, 2016
@sam-github Yes, working as intended, especially for library use. For node programs where passing the node argument passing is obfuscated, an ENV interface that you mentioned would improve the UX imo.
Is there an open issue or PR for that work I can reference here then close this one?
jasnell commentedon Nov 18, 2016
@bcomnes no PR that I'm aware of.
bcomnes commentedon Nov 18, 2016
One other approach I realized is just modifying the shebang with the desired flags. Good enough for me.