Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: defensive fetch, handle failures (#1685)

Myles Scolnick82d852a92839
diff --git a/frontend/src/core/codemirror/language/markdown.ts b/frontend/src/core/codemirror/language/markdown.ts
index a5f5b3b69b..21a9bc57bb 100644
--- a/frontend/src/core/codemirror/language/markdown.ts
+++ b/frontend/src/core/codemirror/language/markdown.ts
@@ -228,7 +228,17 @@ const emojiCompletionSource: CompletionSource = async (context) => {
const getEmojiList = once(async (): Promise<Completion[]> => {
const emojiList = await fetch(
"https://unpkg.com/[email protected]/dist/emoji-en-US.json",
- ).then((res) => res.json() as unknown as Record<string, string[]>);
+ )
+ .then((res) => {
+ if (!res.ok) {
+ throw new Error("Failed to fetch emoji list");
+ }
+ return res.json() as unknown as Record<string, string[]>;
+ })
+ .catch(() => {
+ // If we can't fetch the emoji list, just return an empty list
+ return {};
+ });
return Object.entries(emojiList).map(([emoji, names]) => ({
shortcode: names[0],
diff --git a/frontend/src/core/pyodide/store.ts b/frontend/src/core/pyodide/store.ts
index 6a3363fe6e..23699cb417 100644
--- a/frontend/src/core/pyodide/store.ts
+++ b/frontend/src/core/pyodide/store.ts
@@ -56,7 +56,7 @@ const remoteDefaultFileStore: FileStore = {
readFile() {
const baseURI = document.baseURI;
return fetch(`${baseURI}files/wasm-intro.py`)
- .then((res) => res.text())
+ .then((res) => (res.ok ? res.text() : null))
.catch(() => null);
},
};