{"record":{"id":"1e66744c1dbb8b67","repo":"RocketChat/Rocket.Chat","slug":"failed-to-parse-app-json-e-instanceof-error-e","errorCode":null,"errorMessage":"Failed to parse app.json: ${e instanceof Error ? e.message : String(e)}","messagePattern":"Failed to parse app\\.json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/meteor/client/views/marketplace/lib/getManifestFromZippedApp.ts","lineNumber":28,"sourceCode":"\t\tfileReader.onload = (e): void => resolve(new Uint8Array((e.target as any).result as Uint8Array));\n\t\tfileReader.onerror = (e): void => reject(e);\n\t\tfileReader.readAsArrayBuffer(file);\n\t});\n}\n\nfunction unzipAppBuffer(zippedAppBuffer: Uint8Array): Uint8ArrayObject {\n\treturn unzipSync(zippedAppBuffer);\n}\n\nfunction getAppManifest(unzippedAppBuffer: Uint8ArrayObject): AppManifestSchema {\n\tif (!unzippedAppBuffer['app.json']) {\n\t\tthrow new Error('No app.json file found in the zip');\n\t}\n\n\ttry {\n\t\treturn JSON.parse(strFromU8(unzippedAppBuffer['app.json']));\n\t} catch (e) {\n\t\tthrow new Error(`Failed to parse app.json: ${e instanceof Error ? e.message : String(e)}`);\n\t}\n}\n\nasync function unzipZippedApp(zippedApp: File | Uint8Array): Promise<Uint8ArrayObject> {\n\ttry {\n\t\tif (zippedApp instanceof File) {\n\t\t\tzippedApp = await fileToUint8Array(zippedApp);\n\t\t}\n\n\t\treturn unzipAppBuffer(zippedApp);\n\t} catch (e) {\n\t\tconsole.error(e);\n\t\tthrow e;\n\t}\n}\n\nexport async function getManifestFromZippedApp(zippedApp: File): Promise<AppManifestSchema> {\n\tconst unzippedBuffer = await unzipZippedApp(zippedApp);","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/client/views/marketplace/lib/getManifestFromZippedApp.ts#L10-L46","documentation":"Thrown by getAppManifest when JSON.parse fails on the contents of app.json from the unzipped archive. The file exists (the 'No app.json' check passed) but its content is not valid JSON. The error message includes the underlying parse error message for debugging. strFromU8 converts the raw bytes to a UTF-8 string before parsing.","triggerScenarios":"The app.json file has a JSON syntax error (trailing comma, unquoted keys, single quotes, missing braces). The file is not actually JSON (e.g., it is YAML, TOML, or plain text that was misnamed). Encoding issue: the file is UTF-16 or has a BOM that breaks JSON.parse. The file is empty or truncated.","commonSituations":"Developer hand-edits app.json and introduces a syntax error. Build tool misconfigures the manifest format. File encoding mismatch (UTF-16 from Windows editors). Corrupted download/transfer. Minification or transformation tool mangled the JSON.","solutions":["Validate app.json with a JSON linter or jsonlint before packaging the app.","Ensure app.json is UTF-8 encoded without BOM.","Use the rc-apps build tool which validates the manifest during build.","Read the error message embedded in the thrown error to find the exact JSON syntax issue."],"exampleFix":"// before: app.json with trailing comma\n// { \"id\": \"myapp\", \"version\": \"1.0.0\", }\n// after: valid JSON\n// { \"id\": \"myapp\", \"version\": \"1.0.0\" }","handlingStrategy":"try-catch","validationCode":"const raw = strFromU8(unzippedAppBuffer['app.json']);\ntry {\n  JSON.parse(raw);\n} catch (e) {\n  console.error('app.json parse error:', e.message);\n  // show specific JSON validation error to the developer\n}","typeGuard":"const isValidJson = (str: string): boolean => {\n  try { JSON.parse(str); return true; } catch { return false; }\n};","tryCatchPattern":"try {\n  const manifest = await getManifestFromZippedApp(zipFile);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to parse app.json')) {\n    // e.message contains the underlying JSON parse error for debugging\n    showManifestParseError(e.message);\n    return;\n  }\n  throw e;\n}","preventionTips":["Validate app.json with a JSON linter before packaging.","Ensure app.json is UTF-8 encoded without BOM.","Use rc-apps build which validates the manifest format.","Read the embedded parse error message to pinpoint syntax issues."],"tags":["app-engine","marketplace","json","manifest","validation","file-parsing"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}