Skip to content

Commit 20dadf9

Browse files
authored
Highlight warnOnce warnings under node (#17477)
On the web we don't need do this since console.warn are already shown as warnings. However, under node its nice if the warnings stand out from other stuff being written to stderr.
1 parent 7a209e7 commit 20dadf9

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/library.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,9 @@ mergeInto(LibraryManager.library, {
24162416
if (!warnOnce.shown) warnOnce.shown = {};
24172417
if (!warnOnce.shown[text]) {
24182418
warnOnce.shown[text] = 1;
2419+
#if ENVIRONMENT_MAY_BE_NODE
2420+
if (ENVIRONMENT_IS_NODE) text = 'warning: ' + text;
2421+
#endif
24192422
err(text);
24202423
}
24212424
},

tests/other/test_fflush.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Hey1
2-
stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.
2+
warning: stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.
33
(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)

tests/other/test_fflush_fs.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Hey1
2-
stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.
2+
warning: stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.

tests/test_other.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3773,7 +3773,7 @@ def test_no_exit_runtime_warnings_flush(self):
37733773
#endif
37743774
}
37753775
''')
3776-
warning = 'stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1'
3776+
warning = 'warning: stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1'
37773777

37783778
def test(cxx, no_exit, assertions, flush=0, keepalive=0, filesystem=1):
37793779
if cxx:
@@ -12298,3 +12298,20 @@ def test_bigint64array_polyfill(self):
1229812298

1229912299
for m, [v1, v2] in output['assertEquals']:
1230012300
self.assertEqual(v1, v2, msg=m)
12301+
12302+
def test_warn_once(self):
12303+
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$warnOnce'])
12304+
create_file('main.c', r'''\
12305+
#include <stdio.h>
12306+
#include <emscripten.h>
12307+
12308+
int main() {
12309+
EM_ASM({
12310+
warnOnce("foo");
12311+
// Second call should not output anything
12312+
warnOnce("foo");
12313+
});
12314+
printf("done\n");
12315+
}
12316+
''')
12317+
self.do_runf('main.c', 'warning: foo\ndone\n')

0 commit comments

Comments
 (0)