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:
Antonio Cuni
2022-10-04 19:59:59 +02:00
committed by GitHub
parent e8e2e65584
commit 1e05ff7c95
3 changed files with 40 additions and 2 deletions

View File

@@ -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 &lt;py-config&gt; 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));
}