paperclipai/paperclip · error · Error

Source instance uses postgres mode but has no connection str

Error message

Source instance uses postgres mode but has no connection string in config or adjacent .env.

What it means

Thrown by resolveSourceConnectionString when the source config has database.mode === 'postgres' but neither the adjacent .env's DATABASE_URL nor config.database.connectionString yields a connection string. The reseed needs a live postgres URL to dump/copy from the source.

Source

Thrown at cli/src/commands/worktree.ts:1027

    throw new Error(extractExecSyncErrorMessage(error) ?? String(error));
  }

  installDependenciesBestEffort(targetPath);

  return {
    rootPath: targetPath,
    configPath: path.resolve(targetPath, ".paperclip", "config.json"),
    label: branchName,
    branchName,
    created: true,
  };
}

function resolveSourceConnectionString(config: PaperclipConfig, envEntries: Record<string, string>, portOverride?: number): string {
  if (config.database.mode === "postgres") {
    const connectionString = nonEmpty(envEntries.DATABASE_URL) ?? nonEmpty(config.database.connectionString);
    if (!connectionString) {
      throw new Error(
        "Source instance uses postgres mode but has no connection string in config or adjacent .env.",
      );
    }
    return connectionString;
  }

  const port = portOverride ?? config.database.embeddedPostgresPort;
  return `postgres://paperclip:paperclip@127.0.0.1:${port}/paperclip`;
}

export function copySeededSecretsKey(input: {
  sourceConfigPath: string;
  sourceConfig: PaperclipConfig;
  sourceEnvEntries: Record<string, string>;
  targetKeyFilePath: string;
}): void {
  if (input.sourceConfig.secrets.provider !== "local_encrypted") {
    return;

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Set DATABASE_URL in the source instance's adjacent .env (or connectionString in config.json) to the postgres connection string.
  2. Confirm the .env file is readable by the CLI user and not gitignored away.
  3. If the source uses embedded-postgres mode instead, change config.database.mode to 'embedded-postgres' so the default localhost URL applies.
  4. Verify readPaperclipEnvEntries is loading the correct .env next to the source config.

Example fix

# before: source .env has no DATABASE_URL
# after
DATABASE_URL=postgres://user:pass@host:5432/paperclip
Defensive patterns

Strategy: validation

Validate before calling

function hasSourceConnectionString(config: PaperclipConfig, env: Record<string, string>): boolean {
  return config.database.mode !== 'postgres' || Boolean(nonEmpty(env.DATABASE_URL) ?? nonEmpty(config.database.connectionString));
}

Prevention

When it happens

Trigger: Source instance configured for external postgres but DATABASE_URL was never set; .env missing or not loaded; connectionString field omitted from config.json; secrets stripped from config for security.

Common situations: Source .env not copied during clone; DATABASE_URL set only in the running process env, not in the file; config generated by a template that omits connectionString; switching a source instance to postgres mode without populating the URL.

Related errors


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/d857345f9228636f. Report an issue: GitHub.