{"record":{"id":"ca77b36b194d1e54","repo":"stablyai/orca","slug":"could-not-read-keybindings-file","errorCode":null,"errorMessage":"Could not read keybindings file.","messagePattern":"Could not read keybindings file\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/keybindings/keybinding-file.ts","lineNumber":396,"sourceCode":"    throw new Error(`Could not normalize legacy binding for \"${failedActionIds.join('\", \"')}\".`)\n  }\n  return { seeded: pins.length > 0, snapshot }\n}\n\n// Why: the one-shot seed migration and Settings writes must produce the same\n// on-disk document shape; a single assembly path keeps them from drifting.\nfunction writeActivePlatformSection(\n  path: string,\n  platform: NodeJS.Platform,\n  fallbackCommonOverrides: KeybindingOverrides,\n  mutateActivePlatform: (activePlatform: JsonObject) => void\n): KeybindingFileSnapshot {\n  const keybindingPlatform = getKeybindingPlatform(platform)\n  const readResult = readJsonDocument(path)\n  if (!readResult.document) {\n    // Why: writes must never replace a user-owned file that could not be\n    // parsed; callers surface the error (or retry the migration) after repair.\n    throw new Error(readResult.error ?? 'Could not read keybindings file.')\n  }\n  const document = { ...readResult.document }\n  const common = isJsonObject(document.keybindings)\n    ? { ...document.keybindings }\n    : { ...fallbackCommonOverrides }\n  for (const rootKey of Object.keys(document)) {\n    if (isKeybindingActionId(rootKey)) {\n      delete document[rootKey]\n    }\n  }\n  const platforms = isJsonObject(document.platforms) ? { ...document.platforms } : {}\n  const activePlatform = isJsonObject(platforms[keybindingPlatform])\n    ? { ...(platforms[keybindingPlatform] as JsonObject) }\n    : {}\n  mutateActivePlatform(activePlatform)\n\n  document.version = FILE_VERSION\n  document.keybindings = common","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/keybindings/keybinding-file.ts#L378-L414","documentation":"Thrown by writeActivePlatformSection when readJsonDocument(path) cannot produce a document — the file is missing, empty, or unparseable. Writes must never overwrite a user-owned file that failed to parse (it could contain valid-but-unreadable data), so the operation aborts and surfaces readResult.error or this default message.","triggerScenarios":"The keybindings file was truncated, contains invalid JSON (trailing comma, comments), or was deleted while a write was queued. Any write path (override, conflict-resolution, migration) hits this guard first.","commonSituations":"Editor left the file partially written after a crash. Sync conflict produced a corrupt file. User hand-edited with a syntax error. Disk full during a prior write.","solutions":["Open the keybindings file and fix the JSON syntax error (validate with a JSON linter).","If unrecoverable, back up then delete the file so Orca recreates defaults on next write.","Run the migration/repair flow once the file parses.","Ensure no external process is truncating the file mid-write."],"exampleFix":"// before (file content)\n{ \"keybindings\": {, } }\n// after\n{ \"keybindings\": {} }","handlingStrategy":"validation","validationCode":"const readResult = readJsonDocument(path)\nif (!readResult.document) await runKeybindingsFileRepair(path)","typeGuard":"function isReadableJsonDocument(path: string): boolean {\n  return Boolean(readJsonDocument(path).document)\n}","tryCatchPattern":"try { writeKeybindingOverride(path, platform, actionId, bindings) }\ncatch (e) { if (/Could not read keybindings file/.test(String((e as Error).message))) await repairOrResetKeybindingsFile(path); else throw e }","preventionTips":["Keep the keybindings file valid JSON; lint after hand edits.","Back up then delete a corrupt file so defaults regenerate.","Avoid external editors/tools truncating the file mid-write."],"tags":["keybindings","file-io","parse","write"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}