mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 18:55:29 -05:00
detect the case in which multiple <py-config> are listed
Ideally I would like it to be a fatal error, but it's too hard to do it with the current state of the code, will refactor it later (#826)
This commit is contained in:
@@ -8,7 +8,7 @@ import { PyLoader } from './components/pyloader';
|
||||
import { PyodideRuntime } from './pyodide';
|
||||
import { getLogger } from './logger';
|
||||
import { globalLoader, runtimeLoaded, addInitializer } from './stores';
|
||||
import { handleFetchError, globalExport } from './utils'
|
||||
import { handleFetchError, showError, globalExport } from './utils'
|
||||
|
||||
const logger = getLogger('pyscript/main');
|
||||
|
||||
@@ -45,7 +45,18 @@ class PyScriptApp {
|
||||
// XXX: we should actively complain if there are multiple <py-config>
|
||||
// and show a big error. PRs welcome :)
|
||||
logger.info('searching for <py-config>');
|
||||
const el = document.querySelector('py-config');
|
||||
const elements = document.getElementsByTagName('py-config');
|
||||
let el = null;
|
||||
if (elements.length > 0)
|
||||
el = elements[0];
|
||||
if (elements.length >= 2) {
|
||||
// XXX: ideally, I would like to have a way to raise "fatal
|
||||
// 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("Multiple <py-config> tags detected. Only the first is " +
|
||||
"going to be parsed, all the others will be ignored");
|
||||
}
|
||||
this.config = loadConfigFromElement(el);
|
||||
logger.info('config loaded:\n' + JSON.stringify(this.config, null, 2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user