Skip to content

DatabaseError wraps underlying errors without exposing details #744

@willgriffin

Description

@willgriffin

Summary

When database queries fail, the DatabaseError with message "Failed to execute raw query" doesn't expose the underlying database error details, making debugging difficult.

Example

In CI logs, we see:

✗ add_column failed: Failed to execute raw query
✗ add_index failed: Failed to execute raw query

But the actual PostgreSQL error (e.g., "cannot alter column type because an index depends on it" or similar) is not shown.

Location

The error is thrown in the database adapters:

  • packages/sql/src/adapters/postgres.ts
  • packages/sql/src/adapters/sqlite.ts
  • packages/sql/src/adapters/duckdb.ts
throw new DatabaseError("Failed to execute raw query", {
  // cause is set but not displayed in error message
});

Expected Behavior

The error message should include the underlying database error:

✗ add_column failed: Failed to execute raw query: column "meetings" cannot be cast to type jsonb

Or at minimum, the cause should be properly propagated and logged by consumers.

Impact

  • Debugging migration failures requires guessing at the actual database error
  • CI logs don't provide actionable information
  • Developers have to reproduce locally with DEBUG=1 to see actual errors

Proposed Fix

  1. Include the underlying error message in the DatabaseError message
  2. Or ensure the cause chain is properly logged when errors are caught and reported

Example:

throw new DatabaseError(`Failed to execute raw query: ${originalError.message}`, {
  cause: originalError,
  // ...other context
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent: claudeAssign to Claude for autonomous implementationbugSomething isn't workingpriority: highHigh prioritysize: sSmall (2-4 hours)type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions