mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 03:05:38 -05:00
Create error or warning level banners and allow users to close it (#909)
This commit is contained in:
@@ -7,9 +7,10 @@ import { make_PyScript, initHandlers, mountElements } from './components/pyscrip
|
||||
import { PyLoader } from './components/pyloader';
|
||||
import { PyodideRuntime } from './pyodide';
|
||||
import { getLogger } from './logger';
|
||||
import { handleFetchError, showError, globalExport } from './utils';
|
||||
import { handleFetchError, showWarning, globalExport } from './utils';
|
||||
import { calculatePaths } from './plugins/fetch';
|
||||
import { createCustomElements } from './components/elements';
|
||||
import { UserError, withUserErrorHandler } from "./exceptions"
|
||||
|
||||
type ImportType = { [key: string]: unknown };
|
||||
type ImportMapType = {
|
||||
@@ -78,9 +79,9 @@ class PyScriptApp {
|
||||
// errors" and stop the computation, but currently our life cycle
|
||||
// is too messy to implement it reliably. We might want to revisit
|
||||
// this once it's in a better shape.
|
||||
showError(
|
||||
showWarning(
|
||||
'Multiple <py-config> tags detected. Only the first is ' +
|
||||
'going to be parsed, all the others will be ignored',
|
||||
'going to be parsed, all the others will be ignored',
|
||||
);
|
||||
}
|
||||
this.config = loadConfigFromElement(el);
|
||||
@@ -100,12 +101,11 @@ class PyScriptApp {
|
||||
loadRuntime() {
|
||||
logger.info('Initializing runtime');
|
||||
if (this.config.runtimes.length == 0) {
|
||||
showError('Fatal error: config.runtimes is empty');
|
||||
return;
|
||||
throw new UserError('Fatal error: config.runtimes is empty');
|
||||
}
|
||||
|
||||
if (this.config.runtimes.length > 1) {
|
||||
showError('Multiple runtimes are not supported yet. ' + 'Only the first will be used');
|
||||
showWarning('Multiple runtimes are not supported yet.<br />Only the first will be used');
|
||||
}
|
||||
const runtime_cfg = this.config.runtimes[0];
|
||||
this.runtime = new PyodideRuntime(this.config, runtime_cfg.src, runtime_cfg.name, runtime_cfg.lang);
|
||||
@@ -179,6 +179,8 @@ class PyScriptApp {
|
||||
try {
|
||||
await runtime.loadFromFile(paths[i], fetchPaths[i]);
|
||||
} catch (e) {
|
||||
// Remove the loader so users can see the banner better
|
||||
this.loader.remove()
|
||||
//Should we still export full error contents to console?
|
||||
handleFetchError(<Error>e, fetchPaths[i]);
|
||||
}
|
||||
@@ -243,6 +245,6 @@ globalExport('pyscript_get_config', pyscript_get_config);
|
||||
|
||||
// main entry point of execution
|
||||
const globalApp = new PyScriptApp();
|
||||
globalApp.main();
|
||||
withUserErrorHandler(globalApp.main.bind(globalApp));
|
||||
|
||||
export const runtime = globalApp.runtime;
|
||||
|
||||
Reference in New Issue
Block a user