diff --git a/src/pyodide.js b/src/pyodide.js index b0a90ae9e..64612e8d3 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -159,6 +159,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { window.pyodide.loadedPackages[package] = toLoad[package]; } delete window.pyodide._module.monitorRunDependencies; + window.removeEventListener('error', windowErrorHandler); if (!isFirefox) { preloadWasm().then(() => {resolve(`Loaded ${packageList}`)}); } else { @@ -167,6 +168,17 @@ var languagePluginLoader = new Promise((resolve, reject) => { } }; + // Add a handler for any exceptions that are thrown in the process of + // loading a package + var windowErrorHandler = (err) => { + delete window.pyodide._module.monitorRunDependencies; + window.removeEventListener('error', windowErrorHandler); + // Set up a new Promise chain, since this one failed + loadPackagePromise = new Promise((resolve) => resolve()); + reject(err.message); + }; + window.addEventListener('error', windowErrorHandler); + for (let package in toLoad) { let script = document.createElement('script'); let package_uri = toLoad[package]; @@ -280,8 +292,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { Module.checkABI = function(ABI_number) { if (ABI_number !== parseInt('{{ABI}}')) { - console.error(`ABI numbers differ. Expected {{ABI}}, got ${ABI_number}`); - return false; + throw `ABI numbers differ. Expected {{ABI}}, got ${ABI_number}`; } return true; }; diff --git a/test/test_package_loading.py b/test/test_package_loading.py index 790e77fef..89520a340 100644 --- a/test/test_package_loading.py +++ b/test/test_package_loading.py @@ -132,6 +132,14 @@ def test_different_ABI(selenium_standalone): finally: (build_dir / 'numpy-broken.js').unlink() + selenium_standalone.load_package('kiwisolver') + selenium_standalone.run('import kiwisolver') + assert ( + selenium_standalone.run('repr(kiwisolver)') == + "" + ) + def test_load_handle_failure(selenium_standalone): selenium = selenium_standalone