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
- Include the underlying error message in the DatabaseError message
- 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
});
Summary
When database queries fail, the
DatabaseErrorwith message "Failed to execute raw query" doesn't expose the underlying database error details, making debugging difficult.Example
In CI logs, we see:
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.tspackages/sql/src/adapters/sqlite.tspackages/sql/src/adapters/duckdb.tsExpected Behavior
The error message should include the underlying database error:
Or at minimum, the
causeshould be properly propagated and logged by consumers.Impact
Proposed Fix
causechain is properly logged when errors are caught and reportedExample: