Fix error handling

This commit is contained in:
Michael Droettboom 2019-01-22 11:03:28 -05:00 committed by Madhur Tandon
parent a704d5a04b
commit 37b0913563
2 changed files with 21 additions and 2 deletions

View File

@ -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;
};

View File

@ -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)') ==
"<module 'kiwisolver' from "
"'/lib/python3.7/site-packages/kiwisolver.so'>"
)
def test_load_handle_failure(selenium_standalone):
selenium = selenium_standalone