{"record":{"id":"8be7f98b7b860d23","repo":"decolua/9router","slug":"data-dir-configured-is-a-unix-path-on-windo","errorCode":null,"errorMessage":"[DATA_DIR] '${configured}' is a Unix path on Windows → fallback to default","messagePattern":"\\[DATA_DIR\\] '(.+?)' is a Unix path on Windows → fallback to default","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/dataDir.js","lineNumber":21,"sourceCode":"import os from \"os\";\n\nconst APP_NAME = \"9router\";\n\nfunction defaultDir() {\n  if (process.platform === \"win32\") {\n    return path.join(process.env.APPDATA || path.join(os.homedir(), \"AppData\", \"Roaming\"), APP_NAME);\n  }\n  return path.join(os.homedir(), `.${APP_NAME}`);\n}\n\nexport function getDataDir() {\n  const configured = process.env.DATA_DIR;\n  if (!configured) return defaultDir();\n\n  // On Windows, ignore Unix-style absolute paths (e.g. /var/lib/...) that come\n  // from a Linux-targeted .env or Docker config — they are not valid here.\n  if (process.platform === \"win32\" && /^\\//.test(configured)) {\n    console.warn(`[DATA_DIR] '${configured}' is a Unix path on Windows → fallback to default`);\n    return defaultDir();\n  }\n\n  try {\n    fs.mkdirSync(configured, { recursive: true });\n    return configured;\n  } catch (e) {\n    if (e?.code === \"EACCES\" || e?.code === \"EPERM\") {\n      console.warn(`[DATA_DIR] '${configured}' not writable → fallback ~/.${APP_NAME}`);\n      return defaultDir();\n    }\n    throw e;\n  }\n}\n\nexport const DATA_DIR = getDataDir();\n","sourceCodeStart":3,"sourceCodeEnd":38,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/dataDir.js#L3-L38","documentation":"Startup warning from getDataDir() in src/lib/dataDir.js. When DATA_DIR is set on a Windows host but the value is a Unix-style absolute path (starts with '/'), the directory cannot be a valid Windows location, so the function logs this warning and falls back to the default directory (~/.<APP_NAME>). This exists because Linux-targeted .env or Docker configs are commonly reused on Windows.","triggerScenarios":"process.platform === 'win32' and process.env.DATA_DIR matches /^\\// (e.g. DATA_DIR=/var/lib/9router in a .env copied from a Linux box or Docker Compose file).","commonSituations":"Copying a Linux .env to a Windows dev machine; Docker-style env files run natively on Windows; WSL paths used outside WSL; team-shared config with mixed OSes.","solutions":["Set DATA_DIR to a Windows-style path, e.g. DATA_DIR=C:\\\\9router-data or D:/data/9router.","Remove DATA_DIR entirely to use the default ~/.<APP_NAME> location.","Keep OS-specific .env files (.env.windows / .env.linux) or use forward-slash Windows paths (C:/...) which pass the check."],"exampleFix":"// before (.env on Windows)\nDATA_DIR=/var/lib/9router\n// after\nDATA_DIR=C:/9router-data","handlingStrategy":"validation","validationCode":"const d = process.env.DATA_DIR;\nif (process.platform === \"win32\" && d && /^\\//.test(d)) {\n  console.warn(\"DATA_DIR is a Unix path on Windows; set a Windows path like C:/9router-data\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep per-OS .env files and never share Linux paths into Windows configs.","Prefer drive-letter paths with forward slashes (C:/data/9router) — they work cross-tool.","On Windows, omit DATA_DIR and accept the default ~/.<APP_NAME> unless a custom location is required.","Validate the effective data dir at startup and log it."],"tags":["windows","env-var","path","configuration"],"backgroundTag":"invalid-env-var-path","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}