diesel-rs/diesel · critical

Sqlite's documentation state that this case

Error message

Sqlite's documentation state that this case ({}) is not reachable. If you ever see this error message please open an issue at https://github.com/diesel-rs/diesel.

What it means

`value_type_of` maps libsqlite3 column type codes (SQLITE_TEXT/INTEGER/FLOAT/BLOB/NULL) to diesel's `SqliteType`. SQLite documents only those five return values for `sqlite3_column_type`, so any other code triggers `unreachable!`. Seeing it means either an out-of-spec SQLite build/FFI mismatch or a diesel bug.

Solutions

  1. Print/report the unexpected type code in the message and check which value it is.
  2. Use diesel's `bundled` sqlite feature (`libsqlite3-sys` bundled) so SQLite versions match what diesel expects.
  3. Upgrade diesel and libsqlite3-sys to latest; check for duplicate SQLite libraries linked into the binary.
  4. Open an issue at https://github.com/diesel-rs/diesel with the type code if it persists.

Example fix

// before (Cargo.toml)
diesel = { version = "2", features = ["sqlite"] }
// after
diesel = { version = "2", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] }
libsqlite3-sys = { version = "*", features = ["bundled"] } # via diesel's bundled feature
Defensive patterns

Strategy: validation

Validate before calling

// ensure a single, compatible SQLite is linked
// Cargo.toml: rely on diesel's bundled sqlite so libsqlite3-sys versions match
diesel = { version = "2", features = ["sqlite"] }

Prevention

When it happens

Trigger: A `sqlite3_column_type` call returning a code outside {1,2,3,4,5} while constructing `SqliteValue` via `new`, `from_owned_row`, `from_function_row`, or `value_type` — e.g. an FFI mismatch where codes are misinterpreted.

Common situations: Mismatched libsqlite3/linking (bundled vs system SQLite with ABI differences); exotic SQLite forks returning custom codes; corrupted memory/UB from unsound FFI usage; very old diesel against a much newer SQLite.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07). Data as JSON: /api/errors/b7622b1eedac9028. Report an issue: GitHub.

Appendix: source

Thrown at diesel/src/sqlite/connection/sqlite_value.rs:411

        unsafe { value_type_of(self.value) }
    }
}

/// Reads a value's type, which SQLite reports as SQL `NULL` for a failed conversion.
///
/// # Safety
///
/// `value` must point to a live `sqlite3_value`.
unsafe fn value_type_of(value: NonNull<ffi::sqlite3_value>) -> Option<SqliteType> {
    // SAFETY: the caller guarantees a live value, which this call only inspects.
    let tpe = unsafe { ffi::sqlite3_value_type(value.as_ptr()) };
    match tpe {
        ffi::SQLITE_TEXT => Some(SqliteType::Text),
        ffi::SQLITE_INTEGER => Some(SqliteType::Long),
        ffi::SQLITE_FLOAT => Some(SqliteType::Double),
        ffi::SQLITE_BLOB => Some(SqliteType::Binary),
        ffi::SQLITE_NULL => None,
        _ => unreachable!(
            "Sqlite's documentation state that this case ({}) is not reachable. \
             If you ever see this error message please open an issue at \
             https://github.com/diesel-rs/diesel.",
            tpe
        ),
    }
}

impl OwnedSqliteValue {
    /// Copies a value out of a statement or a function argument.
    ///
    /// `Ok(None)` is SQL `NULL`. A failed allocation is an error instead, as reporting
    /// it as `NULL` would hand out a wrong value.
    pub(super) fn copy_from_ptr(
        ptr: NonNull<ffi::sqlite3_value>,
    ) -> QueryResult<Option<OwnedSqliteValue>> {
        // SAFETY: `ptr` points to a live `sqlite3_value` owned by the statement or
        // callback that outlives this call, and reading its type only inspects it.

View on GitHub (pinned to 6fa6ed01b2)