Skip to content

Commit db1e582

Browse files
authored
pythongh-127503: Improve tracebacks on Emscripten when there is a trap (python#131158)
Modifies the behavior of the interpreter on crash under Emscripten: 1. No Python traceback shown on segfault/trap 2. The JavaScript source line is shown The JavaScript source line is super long and completely unenlightening, whereas the Python traceback is very helpful.
1 parent 3618240 commit db1e582

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

Lib/test/test_isinstance.py

+1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def __getattr__(self, attr):
327327
with self.assertRaises(RecursionError):
328328
issubclass(Failure(), int)
329329

330+
@support.skip_emscripten_stack_overflow()
330331
def test_infinite_cycle_in_bases(self):
331332
"""Regression test for bpo-30570."""
332333
class X:

Tools/wasm/emscripten/node_entry.mjs

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const thisProgramIndex = process.argv.findIndex((x) =>
3232

3333
const settings = {
3434
preRun(Module) {
35+
// Globally expose API object so we can access it if we raise on startup.
36+
globalThis.Module = Module;
3537
mountDirectories(Module);
3638
Module.FS.chdir(process.cwd());
3739
Object.assign(Module.ENV, process.env);
@@ -45,4 +47,12 @@ const settings = {
4547
arguments: process.argv.slice(thisProgramIndex + 1),
4648
};
4749

48-
await EmscriptenModule(settings);
50+
try {
51+
await EmscriptenModule(settings);
52+
} catch(e) {
53+
// Show JavaScript exception and traceback
54+
console.warn(e);
55+
// Show Python exception and traceback
56+
Module.__Py_DumpTraceback(2, Module._PyGILState_GetThisThreadState());
57+
process.exit(1);
58+
}

configure

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ AS_CASE([$ac_sys_system],
23702370
dnl Include file system support
23712371
AS_VAR_APPEND([LINKFORSHARED], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"])
23722372
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV"])
2373-
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET"])
2373+
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET,_PyGILState_GetThisThreadState,__Py_DumpTraceback"])
23742374
AS_VAR_APPEND([LINKFORSHARED], [" -sSTACK_SIZE=5MB"])
23752375
23762376
AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [

0 commit comments

Comments
 (0)