{"record":{"id":"08fc6ed401f8ecd1","repo":"langgenius/dify","slug":"cannot-resolve-localappdata-on-windows","errorCode":null,"errorMessage":"cannot resolve %LOCALAPPDATA% on Windows","messagePattern":"cannot resolve %LOCALAPPDATA% on Windows","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/sys/index.ts","lineNumber":107,"sourceCode":"  }),\n  darwin: () => ({\n    id: () => 'darwin',\n    configDir: () => join(homedir(), '.config', SUBDIR),\n    cacheDir: () => join(homedir(), 'Library', 'Caches', SUBDIR),\n    atomicReplace: posixAtomicReplace,\n  }),\n  win32: () => ({\n    id: () => 'win32',\n    configDir: () => {\n      const appData = appDataDir()\n      if (appData === undefined || appData === '')\n        throw new Error('cannot resolve %APPDATA% on Windows')\n      return join(appData, SUBDIR)\n    },\n    cacheDir: () => {\n      const appData = appDataDir()\n      if (appData === undefined || appData === '')\n        throw new Error('cannot resolve %LOCALAPPDATA% on Windows')\n      return join(appData, SUBDIR)\n    },\n    atomicReplace: win32AtomicReplace,\n  }),\n}\n\nconst defaultPlatformFactory: PlatformFactory = () => ({\n  id: () => platform(),\n  configDir: () => join(homedir(), '.config', SUBDIR),\n  cacheDir: () => join(homedir(), '.cache', SUBDIR),\n  atomicReplace: posixAtomicReplace,\n})\n\nexport function resolvePlatform(): Platform {\n  return (platformImpls[platform()] ?? defaultPlatformFactory)()\n}\n","sourceCodeStart":89,"sourceCodeEnd":124,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/cli/src/sys/index.ts#L89-L124","documentation":"Companion to [54]: a bare Error from the win32 cacheDir (sys/index.ts:107). The condition is identical because cacheDir also calls appDataDir(), which is `APPDATA ?? LOCALAPPDATA`. Practically this means: if APPDATA is set, cacheDir succeeds even though its error message names LOCALAPPDATA — the message is somewhat misleading. Only when BOTH are unset/empty does cacheDir throw. The cache dir holds transient data (downloads, temp) and is less critical than config, but its absence still blocks commands that need it.","triggerScenarios":"Same broken-profile conditions as [54]: Windows service accounts, Task Scheduler without profile, minimal containers, non-interactive SSH — all with both APPDATA and LOCALAPPDATA missing. Because appDataDir falls back APPDATA→LOCALAPPDATA, the LOCALAPPDATA-only check in the message never actually runs independently.","commonSituations":"Identical to [54]: stripped Windows environments, SYSTEM account, containers, CI without profile load.","solutions":["Set APPDATA (and LOCALAPPDATA) as described in [54]; setting APPDATA alone satisfies appDataDir for both config and cache.","Prefer setting both for clarity: APPDATA=...Roaming, LOCALAPPDATA=...Local.","For service accounts, load the user profile or set the vars in the task environment.","Note: difyctl's win32 factory does not honor XDG_CACHE_HOME; you must set the Windows env vars."],"exampleFix":"# before — cache dir resolution fails on Windows\n> difyctl <cmd>\nError: cannot resolve %LOCALAPPDATA% on Windows\n\n# after — set both Windows profile env vars\n$env:LOCALAPPDATA = \"$env:USERPROFILE\\AppData\\Local\"\n$env:APPDATA = \"$env:USERPROFILE\\AppData\\Roaming\"\ndifyctl <cmd>","handlingStrategy":"validation","validationCode":"function assertWindowsCacheDir(): void {\n  if (process.platform !== 'win32') return\n  // appDataDir falls back APPDATA ?? LOCALAPPDATA, so either satisfies cacheDir\n  const appData = process.env.APPDATA ?? process.env.LOCALAPPDATA\n  if (appData === undefined || appData === '') {\n    throw new Error('set LOCALAPPDATA (or APPDATA) before running difyctl on Windows')\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Setting APPDATA satisfies both configDir and cacheDir — set it if you can only set one.","Load the user profile for service-account tasks, or set the env vars explicitly.","Don't rely on XDG_CACHE_HOME on Windows — the win32 factory ignores it."],"tags":["windows","environment","cache-dir","platform","appdata"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}