Repository: pyscript/pyscript
File: pyscriptjs/src/components/pyrepl.ts (TypeScript)

Code before:
            this.appendChild(boxDiv);
            this.editor.focus();
            logger.debug(`element ${this.id} successfully connected`);
        }

        get src() {
            return this.getAttribute('src');
        }

        set src(value) {
            this.setAttribute('src', value);
        }

        attributeChangedCallback(name: string, oldVal: string, newVal: string) {
            if (name === 'src' && newVal !== oldVal) {
                void this.loadReplSrc();
            }
        }

        /**
         * Fetch url from src attribute of py-repl tags and
         * preload the code from fetch response into the Corresponding py-repl tag,
         * but please note that they will not be pre-run unless you click the runbotton.
         */
        async loadReplSrc() {
            const response = await fetch(this.src);
            if (!response.ok) {
                logger.error(
                    `loading code from ${this.src} to repl...Failed ${response.status} (${response.statusText})`,
                );
                return;
            }
            const content = await response.text();
            const code = content.replace(/[<&]/g, match => (match === '<' ? '&lt;' : '&amp;'));
            const parentElement = this.querySelector("div[class='cm-content']");
            const { lastElementChild } = parentElement;
            parentElement.replaceChildren(lastElementChild);
            lastElementChild.innerHTML = code;
            logger.info(`loading code from ${this.src} to repl...success`);
        }

        /** Create and configure the codemirror editor
         */
        makeEditor(pySrc: string): EditorView {
            const languageConf = new Compartment();
            const extensions = [
                indentUnit.of('    '),
                basicSetup,
                languageConf.of(python()),
                keymap.of([
                    ...defaultKeymap,

Review comment (suggestion):
Small thing, we should use `robustFetch` here which you can find in`fetch.ts` since this function will do error handling and raise UserError which will create a banner for us 😃 

https://github.com/pyscript/pyscript/blob/main/pyscriptjs/src/fetch.ts#L12

Code after:
            this.editor = this.makeEditor(pySrc);
            const boxDiv = this.makeBoxDiv();
            this.appendChild(boxDiv);
            this.editor.focus();
            logger.debug(`element ${this.id} successfully connected`);
        }

        get src() {
            return this.getAttribute('src');
        }

        set src(value) {
            this.setAttribute('src', value);
        }

        attributeChangedCallback(name: string, oldVal: string, newVal: string) {
            if (name === 'src' && newVal !== oldVal) {
                void this.loadReplSrc();
            }
        }

        /**
         * Fetch url from src attribute of py-repl tags and
         * preload the code from fetch response into the Corresponding py-repl tag,
         * but please note that they will not be pre-run unless you click the runbotton.
         */
        async loadReplSrc() {
            try {
                const response = await robustFetch(this.src);
                if (!response.ok) {
                    return;
                }
                const cmcontentElement = this.querySelector("div[class='cm-content']");
                const { lastElementChild } = cmcontentElement;
                cmcontentElement.replaceChildren(lastElementChild);
                lastElementChild.textContent = await response.text();
                logger.info(`loading code from ${this.src} to repl...success`);
            } catch (err) {
                const e = err as Error;
                _createAlertBanner(e.message);
            }
        }

        /** Create and configure the codemirror editor
         */
        makeEditor(pySrc: string): EditorView {
            const languageConf = new Compartment();
            const extensions = [
                indentUnit.of('    '),
                basicSetup,
                languageConf.of(python()),