{"record":{"id":"7ddf7259469c0ae4","repo":"dubinc/dub","slug":"failed-to-create-or-update-config-file","errorCode":null,"errorMessage":"Failed to create or update config file","messagePattern":"Failed to create or update config file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/config.ts","lineNumber":48,"sourceCode":"\n  return await configStore.all;\n}\n\nexport async function setConfig(\n  newConfig: Partial<DubConfig>,\n): Promise<DubConfig> {\n  const configStore = new Configstore(\"dub-cli\");\n  const existingConfig: DubConfig = configStore.all;\n\n  const updatedConfig: DubConfig = {\n    ...existingConfig,\n    ...newConfig,\n  };\n\n  configStore.set(updatedConfig);\n\n  if (!configStore.path) {\n    throw new Error(\"Failed to create or update config file\");\n  }\n\n  return updatedConfig;\n}\n","sourceCodeStart":30,"sourceCodeEnd":53,"githubUrl":"https://github.com/dubinc/dub/blob/f216b94a24ca5a0a48c6543ee10392c9006c8b75/packages/cli/src/utils/config.ts#L30-L53","documentation":"setConfig writes merged config into the Configstore, then sanity-checks configStore.path. If the path is falsy, Configstore failed to resolve/create the backing file, so persistence cannot be guaranteed and the CLI throws. It indicates a filesystem/configstore setup problem rather than bad data.","triggerScenarios":"Calling setConfig (directly or via `dub config`/`dub config --info`/server flows) when Configstore cannot determine a file path — typically when HOME or XDG_CONFIG_HOME is unset or points somewhere unwritable, so no default config path can be constructed.","commonSituations":"CI containers running as non-root with no HOME set; read-only filesystems; stripped environments (e.g. cron, Lambda) lacking HOME env var during `dub login` or config updates.","solutions":["Ensure HOME (or XDG_CONFIG_HOME) is set and writable before running the CLI (e.g. export HOME=/root).","Check the target config directory (~/.config/configstore) exists and is writable by the current user.","Re-run the command that saved the config (e.g. `dub login`) after fixing the environment.","If unwritable FS is intentional, mount a writable volume for the config path."],"exampleFix":"// before (CI)\n- run: dub login\n// after\n- run: |\n    export HOME=/home/ci\n    dub login","handlingStrategy":"validation","validationCode":"function assertWritableConfigEnv() {\n  const home = process.env.HOME ?? process.env.XDG_CONFIG_HOME;\n  if (!home) throw new Error(\"HOME or XDG_CONFIG_HOME must be set to save dub config\");\n  fs.mkdirSync(path.join(home, \".config\", \"configstore\"), { recursive: true });\n  fs.accessSync(path.join(home, \".config\"), fs.constants.W_OK);\n}\nassertWritableConfigEnv();","typeGuard":"function hasConfigPath(store: { path?: string }): store is { path: string } {\n  return typeof store.path === \"string\" && store.path.length > 0;\n}","tryCatchPattern":"try {\n  await setConfig({ accessToken });\n} catch (e) {\n  if ((e as Error).message === \"Failed to create or update config file\") {\n    console.error(\"Cannot write config: check HOME is set and ~/.config is writable.\");\n  } else throw e;\n}","preventionTips":["Always set HOME in CI containers (export HOME=/home/runner).","Mount a writable volume for ~/.config in read-only filesystems.","Run the CLI as a user with write access to the config directory.","Smoke-test config writes (`dub config`) in new environments before relying on them."],"tags":["filesystem","cli","config"],"backgroundTag":"unwritable-config-path","analyzedSha":"f216b94a24ca5a0a48c6543ee10392c9006c8b75","analyzedAt":"2026-08-31T18:35:50.395Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}