{"record":{"id":"11d0b08f51aa84d9","repo":"jely2002/youtube-dl-gui","slug":"failed-to-initialize-stronghold-initstatus-initerror","errorCode":null,"errorMessage":"Failed to initialize stronghold: ${initStatus.initError}","messagePattern":"Failed to initialize stronghold: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/stores/stronghold.ts","lineNumber":57,"sourceCode":"      status.value.unlocked = true;\n\n      availableKeys.value = await invoke('stronghold_keys');\n    } else if (!strongholdStatus.unlocked && !strongholdStatus.initError) {\n      status.value.unlocked = false;\n    } else {\n      status.value.unlocked = false;\n      status.value.initError = strongholdStatus.initError ?? 'Unknown error.';\n      throw new Error(`Failed to retrieve stronghold status: ${strongholdStatus.initError}`);\n    }\n    return status.value;\n  }\n\n  async function initialize(): Promise<StrongholdStatus> {\n    const initStatus: StrongholdInitPayload = await invoke('stronghold_init');\n    if (initStatus.initError) {\n      status.value.initError = initStatus.initError;\n      status.value.unlocked = false;\n      throw new Error(`Failed to initialize stronghold: ${initStatus.initError}`);\n    }\n    status.value.unlocked = initStatus.unlocked;\n\n    availableKeys.value = await invoke('stronghold_keys');\n    return status.value;\n  }\n\n  async function getValues(): Promise<StrongholdFields> {\n    const keys = Object.values(STRONGHOLD_KEYS);\n    const entries = await invoke<Record<string, number[] | null>>('stronghold_get', { keys });\n    const decoder = new TextDecoder();\n\n    const result = {} as StrongholdFields;\n    for (const [field, path] of Object.entries(STRONGHOLD_KEYS)) {\n      const raw = entries[path];\n      if (raw == null) {\n        result[field as keyof StrongholdFields] = null;\n      } else {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/jely2002/youtube-dl-gui/blob/c402ee39c0eabab68934c48f8b787ff37a1577b0/src/stores/stronghold.ts#L39-L75","documentation":"initialize invokes 'stronghold_init' in the Rust backend to create/unlock the stronghold. If the returned payload carries initError, the store stores it, marks the vault unlocked=false, and throws 'Failed to initialize stronghold: ${initError}'. It prevents treating a failed init as a usable vault.","triggerScenarios":"invoke('stronghold_init') responds with initError — bad password on unlock attempt, snapshot corruption, disk/permission problems writing the snapshot, or an incompatible stronghold version on the backend.","commonSituations":"User enters the wrong vault password; the app was killed mid-write leaving a truncated snapshot; read-only install directory or sandbox blocking snapshot writes; upgrading the app across an incompatible stronghold format.","solutions":["Surface status.value.initError to the user; for password errors prompt to retry with the correct password.","If the snapshot is corrupt, move/delete it and call initialize again to create a fresh vault.","Check that the app's data directory is writable and the disk is not full.","Catch the error in the UI and show a recovery flow rather than an unhandled rejection."],"exampleFix":"// before\nawait strongholdStore.initialize();\n// after\ntry {\n  await strongholdStore.initialize();\n} catch {\n  showError(strongholdStore.status.initError); // e.g. wrong password\n}","handlingStrategy":"try-catch","validationCode":"if (!password || password.length === 0) {\n  throw new Error('Password required to initialize stronghold');\n}","typeGuard":"const initSucceeded = (s: StrongholdInitPayload): boolean => !s.initError;","tryCatchPattern":"try {\n  await strongholdStore.initialize();\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to initialize stronghold')) {\n    promptRetryPassword(); // most common cause: wrong password\n    return;\n  }\n  throw e;\n}","preventionTips":["Validate the password is present and meets rules before calling initialize.","Never hard-kill the app during a snapshot write; flush before exit.","Ensure the data directory is writable and migrate snapshots across app version upgrades."],"tags":["tauri","stronghold","vault","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"c402ee39c0eabab68934c48f8b787ff37a1577b0","analyzedAt":"2026-09-12T02:01:12.452Z","contentChangedAt":"2026-09-12T02:01:12.452Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}