transact-rs/sqlx · error

unimplemented!()

Error message

unimplemented!()

What it means

`Connection::to_url_lossy` is a required trait method with a default implementation that panics via `unimplemented!()`. The sqlx trait provides this default so drivers that have not yet implemented URL-lossy stringification fail loudly at runtime instead of returning wrong data. Any call to `to_url_lossy` on a driver that does not override it panics.

Source

Thrown at sqlx-core/src/connection.rs:253

    /// * Password
    /// * Hostname
    /// * Port
    /// * Database name
    /// * Unix socket or SQLite database file path
    /// * SSL mode (if applicable)
    /// * SSL CA certificate path
    /// * SSL client certificate path
    /// * SSL client key path
    ///
    /// Additional settings are driver-specific. Refer to the source of a given implementation
    /// to see which options are preserved in the URL.
    ///
    /// ### Panics
    /// This defaults to `unimplemented!()`.
    ///
    /// Individual drivers should override this to implement the intended behavior.
    fn to_url_lossy(&self) -> Url {
        unimplemented!()
    }

    /// Establish a new database connection with the options specified by `self`.
    fn connect(&self) -> impl Future<Output = Result<Self::Connection, Error>> + Send + '_
    where
        Self::Connection: Sized;

    /// Log executed statements with the specified `level`
    fn log_statements(self, level: LevelFilter) -> Self;

    /// Log executed statements with a duration above the specified `duration`
    /// at the specified `level`.
    fn log_slow_statements(self, level: LevelFilter, duration: Duration) -> Self;

    /// Entirely disables statement logging (both slow and regular).
    fn disable_statement_logging(self) -> Self {
        self.log_statements(LevelFilter::Off)
            .log_slow_statements(LevelFilter::Off, Duration::default())

View on GitHub (pinned to 03af8bcc57)

Solutions

  1. Do not call `to_url_lossy()` generically; render connection info per concrete driver type instead
  2. Update the driver crate (e.g. sqlx-postgres/sqlx-mysql) to a version that overrides `to_url_lossy`
  3. If you maintain a custom driver, implement `to_url_lossy` by building a `Url` from your connection options

Example fix

// before
let url = conn.to_url_lossy(); // panics for drivers without an override
// after
let url = match &opts {
    AnyConnectOptions::Postgres(p) => p.to_url_lossy(),
    AnyConnectOptions::MySql(m) => m.to_url_lossy(),
    _ => Url::parse("db://<redacted>").unwrap(),
};
Defensive patterns

Strategy: fallback

Validate before calling

fn supports_to_url_lossy<D: Connection>(_: &D) -> bool { /* check driver feature via docs/tests */ true }

Type guard

fn is_postgres(c: &AnyConnection) -> bool { matches!(c.kind, AnyConnectionKind::Postgres) }

Try / catch

// Rust panics cannot be caught without panic::catch_unwind
let url = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.to_url_lossy()))
    .unwrap_or_else(|_| Url::parse("db://unknown").unwrap());

Prevention

When it happens

Trigger: Calling `to_url_lossy()` on a connection/options object whose driver type does not override the default `unimplemented!()` body, e.g. calling it on a generic `impl Connection` or on a driver that never implemented the method.

Common situations: Generic logging/diagnostic code that tries to render any connection as a URL; code written against an older sqlx driver version before the driver implemented `to_url_lossy`; third-party or custom driver implementations that skipped the override.

Related errors


AI-assisted analysis of transact-rs/sqlx@03af8bcc57 (2026-09-03). Data as JSON: /api/errors/ba60043d8dcd1665. Report an issue: GitHub.