From 1a2f468090cfb2a1435d045489d5ca5c4ea68e89 Mon Sep 17 00:00:00 2001 From: lms Date: Wed, 30 Jul 2025 02:48:51 +0200 Subject: [PATCH 1/3] Give better error message when manifest.toml does not exist --- backend/appInfo.test.ts | 20 ++++++----------- backend/appInfo.ts | 49 ++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/backend/appInfo.test.ts b/backend/appInfo.test.ts index 7c1807b..5afdc2e 100644 --- a/backend/appInfo.test.ts +++ b/backend/appInfo.test.ts @@ -181,7 +181,7 @@ test("url app info with manifest without name", async () => { expect(appInfo.location).toEqual(location); expect(appInfo.manifest).toEqual({ - name: "No entry in manifest.toml (running from URL)", + name: "Missing name entry in manifest.toml", sourceCodeUrl: "http://example.com", manifestFound: true, }); @@ -205,18 +205,12 @@ test("url app info with broken manifest", async () => { fetch.isRedirect = () => false; const location = getLocation("http://localhost:3000") as UrlLocation; - try { - await getAppInfoUrl(location, fetch); - } catch (e) { - if (e instanceof AppInfoError) { - expect(e.message).toEqual( - "Invalid manifest.toml, please check the format", - ); - } else { - throw e; - } - } - expect.assertions(1); + const appInfo = await getAppInfoUrl(location, fetch); + expect(appInfo.manifest).toEqual({ + name: undefined, + sourceCodeUrl: undefined, + manifestFound: false, + }); }); test("url app info with manifest and source code URL", async () => { diff --git a/backend/appInfo.ts b/backend/appInfo.ts index 75987b8..7f1fe93 100644 --- a/backend/appInfo.ts +++ b/backend/appInfo.ts @@ -30,6 +30,12 @@ export type AppInfo = { export class AppInfoError extends Error {} +const MISSING_MANIFEST = { + name: undefined, + sourceCodeUrl: undefined, + manifestFound: false, +}; + export async function getAppInfo(location: Location): Promise { if (location.type === "url") { try { @@ -72,19 +78,10 @@ async function getManifestInfoFromUrl( } const response = await fetch(url + "manifest.toml"); if (!response.ok) { - return { - name: "Unknown (running from URL)", - sourceCodeUrl: undefined, - manifestFound: false, - }; + console.error("Missing manifest.toml (from URL)"); + return { ...MISSING_MANIFEST, name: "Unknown (running from URL)" }; } - const body = await response.text(); - const parsed = tomlParse(body); - return { - name: parsed.name || "No entry in manifest.toml (running from URL)", - sourceCodeUrl: parsed.source_code_url, - manifestFound: true, - }; + return tomlParse(await response.text()); } async function getIconInfoFromUrl( @@ -117,26 +114,24 @@ function getManifestInfoFromDir( ): ManifestInfo { const tomlBuffer = readFileBuffer(path.join(dir, "manifest.toml")); if (tomlBuffer === null) { - return { - name: fallbackName, - sourceCodeUrl: undefined, - manifestFound: false, - }; + console.error("Missing manifest.toml (from DIR)"); + return { ...MISSING_MANIFEST, name: fallbackName }; } - const parsed = tomlParse(tomlBuffer.toString()); - const name = parsed.name || fallbackName; - return { - name, - sourceCodeUrl: parsed.source_code_url, - manifestFound: true, - }; + return tomlParse(tomlBuffer.toString(), fallbackName); } -function tomlParse(s: string): any { +function tomlParse(s: string, fallbackName: string): any { try { - return toml.parse(s); + const parsed = toml.parse(s); + return { + name: + parsed.name || fallbackName || "Missing name entry in manifest.toml", + sourceCodeUrl: parsed.source_code_url || undefined, + manifestFound: true, + }; } catch (e) { - throw new AppInfoError("Invalid manifest.toml, please check the format"); + console.error("Failed to parse manifest.toml, please check the format!"); + return { ...MISSING_MANIFEST, name: fallbackName }; } } From bcc01a6f50064a29eef65baacedee02223539a73 Mon Sep 17 00:00:00 2001 From: lms Date: Wed, 30 Jul 2025 02:52:12 +0200 Subject: [PATCH 2/3] Make jest a bit more quiet --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdf9fe9..ad94877 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "fix": "prettier --write .", "check": "prettier --check .", "cli": "node dist/backend/cli.js", - "test": "jest", + "test": "jest --silent", "typecheck": "tsc --noEmit", "build-backend": "tsc --project tsconfig-backend.json", "build-frontend": "webpack --config webpack.prod.js", From 522638ae70ce8842e0ab90afd65f41ef1956cdf1 Mon Sep 17 00:00:00 2001 From: lms Date: Wed, 30 Jul 2025 02:56:06 +0200 Subject: [PATCH 3/3] Change default name to empty string instead to make build happy --- backend/appInfo.test.ts | 2 +- backend/appInfo.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/appInfo.test.ts b/backend/appInfo.test.ts index 5afdc2e..719be7d 100644 --- a/backend/appInfo.test.ts +++ b/backend/appInfo.test.ts @@ -207,7 +207,7 @@ test("url app info with broken manifest", async () => { const location = getLocation("http://localhost:3000") as UrlLocation; const appInfo = await getAppInfoUrl(location, fetch); expect(appInfo.manifest).toEqual({ - name: undefined, + name: "", sourceCodeUrl: undefined, manifestFound: false, }); diff --git a/backend/appInfo.ts b/backend/appInfo.ts index 7f1fe93..8e118df 100644 --- a/backend/appInfo.ts +++ b/backend/appInfo.ts @@ -120,7 +120,7 @@ function getManifestInfoFromDir( return tomlParse(tomlBuffer.toString(), fallbackName); } -function tomlParse(s: string, fallbackName: string): any { +function tomlParse(s: string, fallbackName: string = ""): any { try { const parsed = toml.parse(s); return {