Skip to content

fix: don't print "undefined" when called with no arguments - #1068

Open
waw666waw666 wants to merge 1 commit into
debug-js:masterfrom
waw666waw666:fix/no-args-undefined
Open

waw666waw666 wants to merge 1 commit into
debug-js:masterfrom
waw666waw666:fix/no-args-undefined

Conversation

@waw666waw666

Copy link
Copy Markdown

Calling a debug instance with no arguments printed undefined as the
message (e.g. probe undefined), because debug() unconditionally wrapped
a non-string first argument in %O — and with no arguments at all,
args[0] is undefined, so the %O formatter inspected a parameter that
was never passed. This treats the zero-argument call like log('') and
leaves the explicit log(undefined) behaviour untouched.

How it was tested:

  • node repro_no_args.js prints probe undefined before the fix and
    probe after it.
  • New tests in test.js (calling with no arguments): log() logs a bare
    namespace line without undefined, and log(undefined) still logs
    undefined. The first test fails with the fix reverted and passes with
    it applied.
  • npx mocha test.js test.node.js: 16 passing before the change,
    18 passing after it (the 2 new tests), no new failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant