{"record":{"id":"9231d7180df25c18","repo":"actualbudget/actual","slug":"actual-data-dir-is-not-set","errorCode":null,"errorMessage":"ACTUAL_DATA_DIR is not set","messagePattern":"ACTUAL_DATA_DIR is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/desktop-electron/window-state.ts","lineNumber":15,"sourceCode":"import fs from 'fs';\nimport path from 'path';\n\nimport electron from 'electron';\nimport type { BrowserWindow } from 'electron';\n\ntype WindowState = Electron.Rectangle & {\n  isMaximized?: boolean;\n  isFullScreen?: boolean;\n  displayBounds?: Electron.Rectangle;\n};\n\nconst getDataDir = () => {\n  if (!process.env.ACTUAL_DATA_DIR) {\n    throw new Error('ACTUAL_DATA_DIR is not set');\n  }\n\n  return process.env.ACTUAL_DATA_DIR;\n};\n\nasync function loadState() {\n  let state: WindowState | undefined = undefined;\n  try {\n    state = JSON.parse(\n      fs.readFileSync(path.join(getDataDir(), 'window.json'), 'utf8'),\n    );\n  } catch {\n    console.log('Could not load window state');\n  }\n\n  return validateState(state);\n}\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/desktop-electron/window-state.ts#L1-L33","documentation":"`getDataDir` in the Electron window-state module reads `ACTUAL_DATA_DIR` to know where to persist window state (position/size) JSON. If the env var is missing it throws rather than guessing a directory, because the desktop app sets this variable during startup.","triggerScenarios":"Calling `loadState()` or `saveState()` from `window-state.ts` when the Electron main process environment lacks `ACTUAL_DATA_DIR` — e.g. launching the app outside its normal launcher scripts.","commonSituations":"Running the electron main file directly with node/electron CLI; custom launchers or test harnesses that don't replicate the production env; refactors that call window-state functions before env setup.","solutions":["Set `ACTUAL_DATA_DIR` to the app's user-data directory (e.g. `app.getPath('userData')`) before loading the window-state module","Launch the app via the standard scripts/builds that set the env var","In tests, set `process.env.ACTUAL_DATA_DIR` to a temp directory in your setup fixture"],"exampleFix":"// before\nimport { loadState } from './window-state';\n// after\nprocess.env.ACTUAL_DATA_DIR ??= app.getPath('userData');\nimport { loadState } from './window-state';","handlingStrategy":"validation","validationCode":"if (!process.env.ACTUAL_DATA_DIR) {\n  process.env.ACTUAL_DATA_DIR = require('electron').app.getPath('userData');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const state = loadState();\n} catch (e) {\n  if (String(e).includes('ACTUAL_DATA_DIR is not set')) {\n    // fall back to defaults / re-set env and retry\n  } else throw e;\n}","preventionTips":["Set ACTUAL_DATA_DIR at the very top of the main process entry, before other imports run","Use app.getPath('userData') as the canonical value","In tests, assign a temp dir in beforeEach"],"tags":["electron","env-var","window-state"],"backgroundTag":"missing-env-var","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}