Skip to content

Commit

Permalink
Report browser exceptions (emscripten-core#8347)
Browse files Browse the repository at this point in the history
This sends clientside browser exceptions to the test runner, and logs them out.

This may help debug failures on our CI, as before this an exception usually just silently hangs the test, and we need to try to reproduce it locally. Now at least we should get a stack trace.
  • Loading branch information
kripken authored and VirtualTim committed May 21, 2019
1 parent d1a9fc3 commit 6af55a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/browser_error_reporting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (typeof window === 'object' && window) {
window.onerror = function(e) {
var xhr = new XMLHttpRequest();
xhr.open('GET', encodeURI('http://localhost:8888?exception=' + e));
xhr.send();
};
}
5 changes: 4 additions & 1 deletion tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def do_GET(self):
self.send_header('Expires', '-1')
self.end_headers()
self.wfile.write(b'OK')
elif 'stdout=' in self.path or 'stderr=' in self.path or 'exception=' in self.path:
elif 'stdout=' in self.path or 'stderr=' in self.path:
'''
To get logging to the console from browser tests, add this to
print/printErr/the exception handler in src/shell.html:
Expand All @@ -1075,6 +1075,8 @@ def do_GET(self):
'''
if DEBUG:
print('[server logging:', urllib.unquote_plus(self.path), ']')
elif 'exception=' in self.path:
print('[client exception:', urllib.unquote_plus(self.path), ']')
elif self.path == '/check':
self.send_response(200)
self.send_header('Content-type', 'text/html')
Expand Down Expand Up @@ -1333,6 +1335,7 @@ def btest(self, filename, expected=None, reference=None, force_c=False,
self.reftest(path_from_root('tests', reference), manually_trigger=manually_trigger_reftest)
if not manual_reference:
args = args + ['--pre-js', 'reftest.js', '-s', 'GL_TESTING=1']
args += ['--pre-js', path_from_root('tests', 'browser_error_reporting.js')]
all_args = [PYTHON, EMCC, '-s', 'IN_TEST_HARNESS=1', filepath, '-o', outfile] + args
# print('all args:', all_args)
try_delete(outfile)
Expand Down

0 comments on commit 6af55a6

Please sign in to comment.