mirror of https://github.com/pyodide/pyodide.git
Fix error handling
This commit is contained in:
parent
a704d5a04b
commit
37b0913563
|
@ -159,6 +159,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
|
||||||
window.pyodide.loadedPackages[package] = toLoad[package];
|
window.pyodide.loadedPackages[package] = toLoad[package];
|
||||||
}
|
}
|
||||||
delete window.pyodide._module.monitorRunDependencies;
|
delete window.pyodide._module.monitorRunDependencies;
|
||||||
|
window.removeEventListener('error', windowErrorHandler);
|
||||||
if (!isFirefox) {
|
if (!isFirefox) {
|
||||||
preloadWasm().then(() => {resolve(`Loaded ${packageList}`)});
|
preloadWasm().then(() => {resolve(`Loaded ${packageList}`)});
|
||||||
} else {
|
} 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) {
|
for (let package in toLoad) {
|
||||||
let script = document.createElement('script');
|
let script = document.createElement('script');
|
||||||
let package_uri = toLoad[package];
|
let package_uri = toLoad[package];
|
||||||
|
@ -280,8 +292,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
|
||||||
|
|
||||||
Module.checkABI = function(ABI_number) {
|
Module.checkABI = function(ABI_number) {
|
||||||
if (ABI_number !== parseInt('{{ABI}}')) {
|
if (ABI_number !== parseInt('{{ABI}}')) {
|
||||||
console.error(`ABI numbers differ. Expected {{ABI}}, got ${ABI_number}`);
|
throw `ABI numbers differ. Expected {{ABI}}, got ${ABI_number}`;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -132,6 +132,14 @@ def test_different_ABI(selenium_standalone):
|
||||||
finally:
|
finally:
|
||||||
(build_dir / 'numpy-broken.js').unlink()
|
(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):
|
def test_load_handle_failure(selenium_standalone):
|
||||||
selenium = selenium_standalone
|
selenium = selenium_standalone
|
||||||
|
|
Loading…
Reference in New Issue