Skip to content

Commit cbc1902

Browse files
authored
Bind err to console.error rather than console.warn (#19326)
Now that we have `dbg()` for debug output (see #19126) we can redirect `err()` to `console.error()` so that folks who call `err()` will get a full stack trace in devtools.
1 parent a36c3f6 commit cbc1902

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.39 (in development)
2222
-----------------------
23+
- The JS `err()` function will now bind to `console.error` by default rather
24+
than `console.warning`. For debugging/tracing/logging we recommend the
25+
`dbg()` function instead. (#19326)
2326

2427
3.1.38 - 05/10/23
2528
-----------------

src/runtime_debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function dbg(text) {
167167
} else
168168
#endif
169169
// TODO(sbc): Make this configurable somehow. Its not always convenient for
170-
// logging to show up as errors.
171-
console.error.apply(console, arguments);
170+
// logging to show up as warnings.
171+
console.warn.apply(console, arguments);
172172
}
173173
#endif

src/shell.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,12 @@ if (ENVIRONMENT_IS_NODE) {
439439

440440
// Set up the out() and err() hooks, which are how we can print to stdout or
441441
// stderr, respectively.
442-
// Normally just binding console.log/console.warn here works fine, but
442+
// Normally just binding console.log/console.error here works fine, but
443443
// under node (with workers) we see missing/out-of-order messages so route
444444
// directly to stdout and stderr.
445445
// See https://github.com/emscripten-core/emscripten/issues/14804
446446
var defaultPrint = console.log.bind(console);
447-
var defaultPrintErr = console.warn.bind(console);
447+
var defaultPrintErr = console.error.bind(console);
448448
if (ENVIRONMENT_IS_NODE) {
449449
defaultPrint = (...args) => fs.writeSync(1, args.join(' ') + '\n');
450450
defaultPrintErr = (...args) => fs.writeSync(2, args.join(' ') + '\n');
@@ -453,7 +453,7 @@ if (ENVIRONMENT_IS_NODE) {
453453
{{{ makeModuleReceiveWithVar('err', 'printErr', 'defaultPrintErr', true) }}}
454454
#else
455455
{{{ makeModuleReceiveWithVar('out', 'print', 'console.log.bind(console)', true) }}}
456-
{{{ makeModuleReceiveWithVar('err', 'printErr', 'console.warn.bind(console)', true) }}}
456+
{{{ makeModuleReceiveWithVar('err', 'printErr', 'console.error.bind(console)', true) }}}
457457
#endif
458458

459459
// Merge back in the overrides

0 commit comments

Comments
 (0)