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
{{ message }}
Repository navigation
Undocumented delete process.env.DEBUG when variable is empty #845
undefined // we lost the DEBUG env already '*' // we get .env file DEBUG setting, but we should have gotten '', because dotenv never overrides set env variables (* actually after version 4 I believe)
problem:
mocha uses the debug package which deletes the env variable. Our user code in bootstrap.js then has no way of knowing if DEBUG was set to an empty string or not supplied. Therefore we get full debug info instead of none.
More general - any code used before using process.env.DEBUG might delete the env variable through just depending on the debug package.
solution
I propose we either not delete the DEBUG variable or have a section in documentation to explain and suggest maybe using DEBUG=, to disable debug logging.
I agree, this is weird behavior. It's being deleted in the method that sets namespaces, which I believe is called implicitly upon importing debug. I'll mark it as a bug.
Unfortunately, the widespread use of debug means changing this would be a breaking change - at least, that's how I'd like to treat it.
The pressure on debug@5 is growing and I'll probably have to address it soon. I've already been discussing a few things with other maintainers about the future of debug and what it looks like, and I imagine v5 will be a complete rewrite at this point.
For now, this might work as an include stub (it's untested, so tread lightly).
// debug-patch.js// XXX Remove when https://github.com/visionmedia/debug/issues/845 is resolved. // Must happen before any other `require('debug')` in the application.constoldEnv=process.env.DEBUG;constdebug=require('debug');debug.save=namespaces=>{process.env.DEBUG=namespaces||'';};process.env.DEBUG=oldEnv;module.exports=debug;
I realize this isn't ideal but I have to be very cautious with which manner I break people.
Sorry for the headache :/ But thanks for reporting this. Not often a real defect comes up here!
Great, thank you for looking into this and keeping the issue open. I think for my use case the patch won't work unfortunately (I start mocha first, which causes an issue, then my user code), but I got around it by using DEBUG=, env value.
Activity
Qix- commentedon Sep 17, 2021
I agree, this is weird behavior. It's being deleted in the method that sets namespaces, which I believe is called implicitly upon importing
debug. I'll mark it as a bug.For reference, it's located here:
https://github.com/visionmedia/debug/blob/d177f2bc36d3b8b8e9b1b006727ef5e04f98eac7/src/node.js#L209
Unfortunately, the widespread use of
debugmeans changing this would be a breaking change - at least, that's how I'd like to treat it.The pressure on
debug@5is growing and I'll probably have to address it soon. I've already been discussing a few things with other maintainers about the future ofdebugand what it looks like, and I imagine v5 will be a complete rewrite at this point.For now, this might work as an include stub (it's untested, so tread lightly).
I realize this isn't ideal but I have to be very cautious with which manner I break people.
Sorry for the headache :/ But thanks for reporting this. Not often a real defect comes up here!
warriorGod commentedon Sep 21, 2021
Great, thank you for looking into this and keeping the issue open. I think for my use case the patch won't work unfortunately (I start mocha first, which causes an issue, then my user code), but I got around it by using
DEBUG=,env value.mosaic4real commentedon Jan 7, 2022