SeaQL/sea-orm · info

Infallible

Error message

Infallible

What it means

This panic comes from `.expect("Infallible")` on a `write!` into an in-memory `String` inside `Identity:: Many` rendering in `src/entity/identity.rs:79`. Writing to a `String` via `fmt::Write` cannot fail (allocation failure aborts instead), so the panic is a defensive assertion on an infallible operation. It is effectively unreachable in normal use; if it ever fires, memory is exhausted or the `Display` impl of an identifier misbehaves.

Source

Thrown at src/entity/identity.rs:79

    fn into_iter(self) -> Self::IntoIter {
        OwnedIdentityIter {
            identity: self,
            index: 0,
        }
    }
}

impl Iden for Identity {
    fn quoted(&self) -> Cow<'static, str> {
        match self {
            Identity::Unary(iden) => iden.inner(),
            Identity::Binary(iden1, iden2) => Cow::Owned(format!("{iden1}{iden2}")),
            Identity::Ternary(iden1, iden2, iden3) => Cow::Owned(format!("{iden1}{iden2}{iden3}")),
            Identity::Many(vec) => {
                let mut s = String::new();
                for iden in vec.iter() {
                    write!(&mut s, "{iden}").expect("Infallible");
                }
                Cow::Owned(s)
            }
        }
    }

    fn to_string(&self) -> String {
        match self.quoted() {
            Cow::Borrowed(s) => s.to_owned(),
            Cow::Owned(s) => s,
        }
    }

    fn unquoted(&self) -> &str {
        panic!("Should not call this")
    }
}

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. No fix needed — this branch is unreachable by construction; do not catch it.
  2. If it fires, check for a custom `Iden`/identifier type whose `Display` implementation returns an error.
  3. Reduce identifier/row batch sizes if memory pressure is the cause.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure identifiers implement Display and batches are bounded
let s: String = vec.iter().map(|i| i.to_string()).collect();
debug_assert!(!s.is_empty() || vec.is_empty());

Type guard

fn is_infallible_write(res: fmt::Result) -> bool { res.is_ok() }

Prevention

When it happens

Trigger: Rendering an `Identity::Many` column identity (e.g. composite primary keys used in `column_tuple_in_condition` or joined-key queries) when `write!` on the internal `String` returns `Err` — practically only under OOM or a buggy custom ` Iden` Display impl.

Common situations: Composite/multi-column primary keys or multi-column foreign keys being converted to string identity during query building; almost never hit by real applications.

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 SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/956c48e339531d66. Report an issue: GitHub.