Skip to content

bug(connection): 'connection failed: db error' swallows actual error cause #707

@NikolayS

Description

@NikolayS

Report

@mlusetti reported on X (2026-03-22): 'Tried it today but simply got "connection failed: db error" with every connection syntax I tried. Even -D option did not produce meaningful output. Classic psql connect smoothly.'

Root cause

In src/connection.rs, map_connect_error() calls e.to_string() on a tokio_postgres::Error. When the error is not a DB-level error (e.g. TCP refused, wrong hostname, network timeout), tokio-postgres displays it as "db error" — the actual cause is buried in the error source chain.

Fix: walk e.source() chain to extract the real underlying IO/network error when e.as_db_error() is None.

Expected

connection to server at "localhost", port 5432 failed: Connection refused (os error 111)

Actual

connection to server at "localhost", port 5432 failed: db error

Additional: -D should show more

The -D flag should print the full error chain including source. Currently doesn't help diagnose connection failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions