dubinc/dub · error

Failed to create or update config file

Error message

Failed to create or update config file

What it means

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.

Source

Thrown at packages/cli/src/utils/config.ts:48

  return await configStore.all;
}

export async function setConfig(
  newConfig: Partial<DubConfig>,
): Promise<DubConfig> {
  const configStore = new Configstore("dub-cli");
  const existingConfig: DubConfig = configStore.all;

  const updatedConfig: DubConfig = {
    ...existingConfig,
    ...newConfig,
  };

  configStore.set(updatedConfig);

  if (!configStore.path) {
    throw new Error("Failed to create or update config file");
  }

  return updatedConfig;
}

View on GitHub (pinned to f216b94a24)

Solutions

  1. Ensure HOME (or XDG_CONFIG_HOME) is set and writable before running the CLI (e.g. export HOME=/root).
  2. Check the target config directory (~/.config/configstore) exists and is writable by the current user.
  3. Re-run the command that saved the config (e.g. `dub login`) after fixing the environment.
  4. If unwritable FS is intentional, mount a writable volume for the config path.

Example fix

// before (CI)
- run: dub login
// after
- run: |
    export HOME=/home/ci
    dub login
Defensive patterns

Strategy: validation

Validate before calling

function assertWritableConfigEnv() {
  const home = process.env.HOME ?? process.env.XDG_CONFIG_HOME;
  if (!home) throw new Error("HOME or XDG_CONFIG_HOME must be set to save dub config");
  fs.mkdirSync(path.join(home, ".config", "configstore"), { recursive: true });
  fs.accessSync(path.join(home, ".config"), fs.constants.W_OK);
}
assertWritableConfigEnv();

Type guard

function hasConfigPath(store: { path?: string }): store is { path: string } {
  return typeof store.path === "string" && store.path.length > 0;
}

Try / catch

try {
  await setConfig({ accessToken });
} catch (e) {
  if ((e as Error).message === "Failed to create or update config file") {
    console.error("Cannot write config: check HOME is set and ~/.config is writable.");
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dubinc/dub@f216b94a24 (2026-08-31). Data as JSON: /api/errors/7ddf7259469c0ae4. Report an issue: GitHub.