coleam00/Archon · critical

Database dialect not initialized. This indicates the databas

Error message

Database dialect not initialized. This indicates the database connection failed during initialization. Check logs for database connection errors.

What it means

getDialect returns the database dialect detected during initialization. If it is still unset after triggering getDatabase(), initialization failed (connection refused, bad DSN, driver error), so it throws explaining that the dialect was never initialized and pointing at connection-error logs. Everything that needs dialect-aware SQL (e.g. dialect.now()) depends on this succeeding.

Source

Thrown at packages/core/src/db/connection.ts:85

        'db.docker_using_sqlite'
      );
    }
  }

  return database;
}

/**
 * Get the SQL dialect for the current database
 */
export function getDialect(): SqlDialect {
  if (!dialect) {
    // Initialize database to set dialect
    getDatabase();
  }

  if (!dialect) {
    throw new Error(
      'Database dialect not initialized. This indicates the database connection failed during initialization. ' +
        'Check logs for database connection errors.'
    );
  }

  return dialect;
}

/**
 * Get the current database type without initializing the database
 * Useful for version/info commands that don't need a connection
 */
export function getDatabaseType(): 'postgresql' | 'sqlite' {
  return process.env.DATABASE_URL ? 'postgresql' : 'sqlite';
}

/**
 * Read the recorded schema vintage (#2316): which Archon build created this database

View on GitHub (pinned to 0773b97458)

Solutions

  1. Fix the database connection: check DATABASE_URL/DSN, server reachability (pg_isready / ping), and credentials.
  2. Read earlier logs for the underlying connection error thrown by getDatabase() — this error is secondary to that one.
  3. Verify the configured dialect is supported (sqlite/postgres) and matches the DSN.
  4. Ensure DB init (getDatabase()) completes at startup before any code path queries the dialect.
  5. If embedded, confirm the SQLite data directory exists and is writable.

Example fix

// before: DSN misconfigured
DATABASE_URL=postgres://localhost:5433/archon  // wrong port
// after
DATABASE_URL=postgres://localhost:5432/archon  # and verify: pg_isready -p 5432
Defensive patterns

Strategy: try-catch

Validate before calling

// health probe before any dialect-dependent query
async function assertDbReady() {
  try { await pool.query('SELECT 1'); } catch (e) {
    throw new Error(`database unreachable at startup: ${e.message}`);
  }
  getDatabase(); // ensures dialect is set
}

Type guard

function isDialectNotInitialized(e: unknown): boolean {
  return e instanceof Error && e.message.startsWith('Database dialect not initialized');
}

Try / catch

try {
  await queryWithDialect(...);
} catch (e) {
  if (isDialectNotInitialized(e)) {
    console.error('DB init failed earlier; check DATABASE_URL and that the server is reachable');
    process.exit(1); // fail fast at boot, not per-request
  }
  throw e;
}

Prevention

When it happens

Trigger: Any call to getDialect()/dialect()/now() before or after a failed getDatabase() initialization — e.g. database server down, wrong DSN, unsupported dialect string in config.

Common situations: Postgres not running or wrong port; DATABASE_URL typo or missing env var; SQLite file path not writable; config dialect set to an unsupported value so getDatabase() threw during boot and left `dialect` unset; calling a query function before the app's DB init step completed.

Related errors


AI-assisted analysis of coleam00/Archon@0773b97458 (2026-09-01). Data as JSON: /api/errors/5d72d432b159e734. Report an issue: GitHub.