Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): readable error for oversized text-viewer files (#1703)

Andrew Mikofalvy65ecf3e614ee
diff --git a/.changeset/textviewer-large-file-error-message.md b/.changeset/textviewer-large-file-error-message.md
new file mode 100644
index 000000000..9772117e8
--- /dev/null
+++ b/.changeset/textviewer-large-file-error-message.md
@@ -0,0 +1,7 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Show a human-readable message when a file is too large for the built-in text editor, instead of a bare "Failed to load file (HTTP 413)".
+
+The built-in text editor caps the file it will load at 1 MB. Opening a larger file (a long GPS track `.gpx`, a big `.csv`, a verbose `.log`) previously surfaced only the raw status code. It now explains that the file exceeds the 1 MB limit and points to the "Open file" action to open it in another app. Other load failures map to plain-language messages too; unexpected statuses keep the code appended so they stay diagnosable.
diff --git a/packages/app/src/components/TextViewer.error-message.dom.test.tsx b/packages/app/src/components/TextViewer.error-message.dom.test.tsx
new file mode 100644
index 000000000..89950d9b6
--- /dev/null
+++ b/packages/app/src/components/TextViewer.error-message.dom.test.tsx
@@ -0,0 +1,66 @@
+import { afterEach, describe, expect, test } from 'bun:test';
+import { cleanup, render, waitFor } from '@testing-library/react';
+
+const { TextViewer } = await import('./TextViewer.tsx');
+
+/** Stub `fetch` with a resolved non-OK response of the given status. The
+ * viewer throws on `!resp.ok` before touching the body, so an empty
+ * `text()` is sufficient. */
+function mockFetchStatus(status: number): typeof globalThis.fetch {
+ return (() =>
+ Promise.resolve({
+ ok: false,
+ status,
+ text: async () => '',
+ } as Response)) as typeof globalThis.fetch;
+}
+
+describe('TextViewer — human-readable load errors', () => {
+ const originalFetch = globalThis.fetch;
+ afterEach(() => {
+ cleanup();
+ globalThis.fetch = originalFetch;
+ });
+
+ test('413 renders a size-limit explanation, not a bare status code', async () => {
+ globalThis.fetch = mockFetchStatus(413);
+ const { container } = render(
+ <TextViewer
+ src="/api/asset-text?path=fishing-log/Morning_Activity.gpx"
+ fileName="Morning_Activity.gpx"
+ extension="gpx"
+ />,
+ );
+ await waitFor(() => {
+ expect(container.querySelector('[data-text-viewer-state="error"]')).not.toBeNull();
+ });
+ const text = container.textContent ?? '';
+ expect(text).toContain('too large to open in the built-in text editor');
+ expect(text).toContain('1 MB limit');
+ expect(text).not.toContain('HTTP 413');
+ });
+
+ test('404 renders a not-found explanation', async () => {
+ globalThis.fetch = mockFetchStatus(404);
+ const { container } = render(
+ <TextViewer src="/api/asset-text?path=gone.csv" fileName="gone.csv" extension="csv" />,
+ );
+ await waitFor(() => {
+ expect(container.querySelector('[data-text-viewer-state="error"]')).not.toBeNull();
+ });
+ expect(container.textContent ?? '').toContain('could not be found');
+ });
+
+ test('an unmapped status keeps the diagnostic code for debuggability', async () => {
+ globalThis.fetch = mockFetchStatus(503);
+ const { container } = render(
+ <TextViewer src="/api/asset-text?path=weird.bin" fileName="weird.bin" extension="bin" />,
+ );
+ await waitFor(() => {
+ expect(container.querySelector('[data-text-viewer-state="error"]')).not.toBeNull();
+ });
+ const text = container.textContent ?? '';
+ expect(text).toContain('Something went wrong opening this file');
+ expect(text).toContain('HTTP 503');
+ });
+});
diff --git a/packages/app/src/components/TextViewer.tsx b/packages/app/src/components/TextViewer.tsx
index e29ca81e6..d3abbe480 100644
--- a/packages/app/src/components/TextViewer.tsx
+++ b/packages/app/src/components/TextViewer.tsx
@@ -57,7 +57,18 @@ function useAssetText(src: string): FetchState {
.then(async (resp) => {
if (!resp.ok) {
const status = resp.status;
- throw new Error(t`Failed to load file (HTTP ${status})`);
+ if (status === 413) {
+ throw new Error(
+ t`This file is too large to open in the built-in text editor (1 MB limit). Use Open file below to open it in another app.`,
+ );
+ }
+ if (status === 404) {
+ throw new Error(t`This file could not be found.`);
+ }
+ if (status === 400) {
+ throw new Error(t`This file can't be opened in the text editor.`);
+ }
+ throw new Error(t`Something went wrong opening this file (HTTP ${status}).`);
}
return resp.text();
})
diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.json
index f890b5bdc..9e9d5e011 100644
--- a/packages/app/src/locales/en/messages.json
+++ b/packages/app/src/locales/en/messages.json
@@ -310,6 +310,7 @@
],
"92rbk2": ["Mirror loading <0>", ["mirrorRef"], "</0>"],
"96G6Re": ["New folder"],
+ "96w9hU": ["Something went wrong opening this file (HTTP ", ["status"], ")."],
"99eR72": ["Visual editor table selection"],
"9Bd18D": ["Failed to load hub pages"],
"9NC_MT": ["Couldn't open ", ["CLAUDE_WEB_FALLBACK_LABEL"], " in your browser."],
@@ -408,6 +409,9 @@
"CTJLpz": ["\"", ["trimmed"], "\" already exists here"],
"CU3AiE": ["Switching branches"],
"CXj9C-": ["New property name"],
+ "C_WGy8": [
+ "This file is too large to open in the built-in text editor (1 MB limit). Use Open file below to open it in another app."
+ ],
"C_cPoW": ["Your GitHub session expired — sign in again to verify push access."],
"ChAtFg": ["You don't have permission to push to this repo"],
"CvsD6Y": ["via ", ["viaTags"]],
@@ -677,6 +681,7 @@
"MrwYIK": ["Toggle a source comment through CodeMirror."],
"MsuXaI": ["Hide panel (", ["panelShortcut"], ")"],
"N1YYa7": ["Loading image"],
+ "N1mdmS": ["This file can't be opened in the text editor."],
"N2FcBE": ["Synced"],
"N2S1rs": ["Empty"],
"N2eHWq": ["Code Block"],
@@ -758,7 +763,6 @@
"PXXeW8": ["Restore this auto-save?"],
"PZt1uN": ["Search files, commands, projects, and AI handoff actions."],
"PZt2Ds": ["Clone ended unexpectedly."],
- "PauP7d": ["Failed to load file (HTTP ", ["status"], ")"],
"PdA9NZ": [["ahead"], " ahead"],
"Pgu10b": ["Saved as <0>", ["slug"], ".md</0>"],
"PgzIpb": ["Move to the previous visual-editor find result."],
@@ -1540,6 +1544,7 @@
"rwrPbS": ["Component boundary navigation"],
"s-MGs7": ["Resources"],
"s-XOaI": ["File name"],
+ "s0IDhW": ["This file could not be found."],
"s1c0ja": ["Bullet List"],
"s3caR3": ["Deleting"],
"sE7R19": [
diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.po
index 3c21b9b5c..64a30eb53 100644
--- a/packages/app/src/locales/en/messages.po
+++ b/packages/app/src/locales/en/messages.po
@@ -2071,10 +2071,6 @@ msgstr "Failed to load documents"
msgid "Failed to load file"
msgstr "Failed to load file"
-#: src/components/TextViewer.tsx
-msgid "Failed to load file (HTTP {status})"
-msgstr "Failed to load file (HTTP {status})"
-
#: src/components/FolderPropertiesCard.tsx
msgid "Failed to load folder properties: {message}"
msgstr "Failed to load folder properties: {message}"
@@ -4884,6 +4880,10 @@ msgstr "Something went wrong loading the settings panel."
msgid "Something went wrong opening \"{docName}\"."
msgstr "Something went wrong opening \"{docName}\"."
+#: src/components/TextViewer.tsx
+msgid "Something went wrong opening this file (HTTP {status})."
+msgstr "Something went wrong opening this file (HTTP {status})."
+
#: src/lib/keyboard-shortcuts.ts
msgid "Source editing"
msgstr "Source editing"
@@ -5245,6 +5245,18 @@ msgstr "This branch is checked out in:"
msgid "This document is already active in the editor. Use Open to collapse the graph."
msgstr "This document is already active in the editor. Use Open to collapse the graph."
+#: src/components/TextViewer.tsx
+msgid "This file can't be opened in the text editor."
+msgstr "This file can't be opened in the text editor."
+
+#: src/components/TextViewer.tsx
+msgid "This file could not be found."
+msgstr "This file could not be found."
+
+#: src/components/TextViewer.tsx
+msgid "This file is too large to open in the built-in text editor (1 MB limit). Use Open file below to open it in another app."
+msgstr "This file is too large to open in the built-in text editor (1 MB limit). Use Open file below to open it in another app."
+
#: src/components/CreateProjectDialog.tsx
msgid "This folder already has files. Add a name to create a new subfolder inside it."
msgstr "This folder already has files. Add a name to create a new subfolder inside it."
diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.json
index 695b42b46..10893b13f 100644
--- a/packages/app/src/locales/pseudo/messages.json
+++ b/packages/app/src/locales/pseudo/messages.json
@@ -310,6 +310,7 @@
],
"92rbk2": ["Ḿĩŕŕōŕ ĺōàďĩńĝ <0>", ["mirrorRef"], "</0>"],
"96G6Re": ["Ńēŵ ƒōĺďēŕ"],
+ "96w9hU": ["Śōḿēţĥĩńĝ ŵēńţ ŵŕōńĝ ōƥēńĩńĝ ţĥĩś ƒĩĺē (ĤŢŢƤ ", ["status"], ")."],
"99eR72": ["Vĩśũàĺ ēďĩţōŕ ţàƀĺē śēĺēćţĩōń"],
"9Bd18D": ["Ƒàĩĺēď ţō ĺōàď ĥũƀ ƥàĝēś"],
"9NC_MT": ["Ćōũĺďń'ţ ōƥēń ", ["CLAUDE_WEB_FALLBACK_LABEL"], " ĩń ŷōũŕ ƀŕōŵśēŕ."],
@@ -408,6 +409,9 @@
"CTJLpz": ["\"", ["trimmed"], "\" àĺŕēàďŷ ēxĩśţś ĥēŕē"],
"CU3AiE": ["Śŵĩţćĥĩńĝ ƀŕàńćĥēś"],
"CXj9C-": ["Ńēŵ ƥŕōƥēŕţŷ ńàḿē"],
+ "C_WGy8": [
+ "Ţĥĩś ƒĩĺē ĩś ţōō ĺàŕĝē ţō ōƥēń ĩń ţĥē ƀũĩĺţ-ĩń ţēxţ ēďĩţōŕ (1 Ḿß ĺĩḿĩţ). Ũśē Ōƥēń ƒĩĺē ƀēĺōŵ ţō ōƥēń ĩţ ĩń àńōţĥēŕ àƥƥ."
+ ],
"C_cPoW": ["Ŷōũŕ ĜĩţĤũƀ śēśśĩōń ēxƥĩŕēď — śĩĝń ĩń àĝàĩń ţō vēŕĩƒŷ ƥũśĥ àććēśś."],
"ChAtFg": ["Ŷōũ ďōń'ţ ĥàvē ƥēŕḿĩśśĩōń ţō ƥũśĥ ţō ţĥĩś ŕēƥō"],
"CvsD6Y": ["vĩà ", ["viaTags"]],
@@ -677,6 +681,7 @@
"MrwYIK": ["Ţōĝĝĺē à śōũŕćē ćōḿḿēńţ ţĥŕōũĝĥ ĆōďēḾĩŕŕōŕ."],
"MsuXaI": ["Ĥĩďē ƥàńēĺ (", ["panelShortcut"], ")"],
"N1YYa7": ["Ĺōàďĩńĝ ĩḿàĝē"],
+ "N1mdmS": ["Ţĥĩś ƒĩĺē ćàń'ţ ƀē ōƥēńēď ĩń ţĥē ţēxţ ēďĩţōŕ."],
"N2FcBE": ["Śŷńćēď"],
"N2S1rs": ["Ēḿƥţŷ"],
"N2eHWq": ["Ćōďē ßĺōćķ"],
@@ -758,7 +763,6 @@
"PXXeW8": ["Ŕēśţōŕē ţĥĩś àũţō-śàvē?"],
"PZt1uN": ["Śēàŕćĥ ƒĩĺēś, ćōḿḿàńďś, ƥŕōĴēćţś, àńď ÀĨ ĥàńďōƒƒ àćţĩōńś."],
"PZt2Ds": ["Ćĺōńē ēńďēď ũńēxƥēćţēďĺŷ."],
- "PauP7d": ["Ƒàĩĺēď ţō ĺōàď ƒĩĺē (ĤŢŢƤ ", ["status"], ")"],
"PdA9NZ": [["ahead"], " àĥēàď"],
"Pgu10b": ["Śàvēď àś <0>", ["slug"], ".ḿď</0>"],
"PgzIpb": ["Ḿōvē ţō ţĥē ƥŕēvĩōũś vĩśũàĺ-ēďĩţōŕ ƒĩńď ŕēśũĺţ."],
@@ -1540,6 +1544,7 @@
"rwrPbS": ["Ćōḿƥōńēńţ ƀōũńďàŕŷ ńàvĩĝàţĩōń"],
"s-MGs7": ["Ŕēśōũŕćēś"],
"s-XOaI": ["Ƒĩĺē ńàḿē"],
+ "s0IDhW": ["Ţĥĩś ƒĩĺē ćōũĺď ńōţ ƀē ƒōũńď."],
"s1c0ja": ["ßũĺĺēţ Ĺĩśţ"],
"s3caR3": ["Ďēĺēţĩńĝ"],
"sE7R19": [
diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.po
index 0de8a76f4..01a265037 100644
--- a/packages/app/src/locales/pseudo/messages.po
+++ b/packages/app/src/locales/pseudo/messages.po
@@ -2066,10 +2066,6 @@ msgstr ""
msgid "Failed to load file"
msgstr ""
-#: src/components/TextViewer.tsx
-msgid "Failed to load file (HTTP {status})"
-msgstr ""
-
#: src/components/FolderPropertiesCard.tsx
msgid "Failed to load folder properties: {message}"
msgstr ""
@@ -4879,6 +4875,10 @@ msgstr ""
msgid "Something went wrong opening \"{docName}\"."
msgstr ""
+#: src/components/TextViewer.tsx
+msgid "Something went wrong opening this file (HTTP {status})."
+msgstr ""
+
#: src/lib/keyboard-shortcuts.ts
msgid "Source editing"
msgstr ""
@@ -5240,6 +5240,18 @@ msgstr ""
msgid "This document is already active in the editor. Use Open to collapse the graph."
msgstr ""
+#: src/components/TextViewer.tsx
+msgid "This file can't be opened in the text editor."
+msgstr ""
+
+#: src/components/TextViewer.tsx
+msgid "This file could not be found."
+msgstr ""
+
+#: src/components/TextViewer.tsx
+msgid "This file is too large to open in the built-in text editor (1 MB limit). Use Open file below to open it in another app."
+msgstr ""
+
#: src/components/CreateProjectDialog.tsx
msgid "This folder already has files. Add a name to create a new subfolder inside it."
msgstr ""