SeaQL/sea-orm · info
Infallible
Error message
Infallible
What it means
This `.expect("Infallible")` panic occurs in sea-orm's sqlx Postgres `connect` while building the `SET search_path = ...` statement for the configured `schema_search_path`. `write!` into a String cannot actually fail (fmt::Error is treated as infallible here), so the expect should never fire in practice; it is an internal invariant guard. Seeing it would indicate an extreme condition such as memory allocation failure during string formatting.
Source
Thrown at src/driver/sqlx_postgres.rs:101
}
}
if let Some(application_name) = &options.application_name {
sqlx_opts = sqlx_opts.application_name(application_name);
}
if let Some(timeout) = options.statement_timeout {
sqlx_opts = sqlx_opts.options([("statement_timeout", timeout.as_millis().to_string())]);
}
if let Some(f) = &options.pg_opts_fn {
sqlx_opts = f(sqlx_opts);
}
let set_search_path_sql = options.schema_search_path.as_ref().map(|schema| {
let mut string = "SET search_path = ".to_owned();
if schema.starts_with('"') {
write!(&mut string, "{schema}").expect("Infallible");
} else {
for (i, schema) in schema.split(',').enumerate() {
if i > 0 {
write!(&mut string, ",").expect("Infallible");
}
if schema.starts_with('"') {
write!(&mut string, "{schema}").expect("Infallible");
} else {
write!(&mut string, "\"{schema}\"").expect("Infallible");
}
}
}
string
});
let lazy = options.connect_lazy;
let after_connect = options.after_connect.clone();
let pg_pool_opts_fn = options.pg_pool_opts_fn.clone();View on GitHub (pinned to e29bcd1b41)
Solutions
- Treat this as an internal invariant: if it fires, check system memory (OOM during allocation) and retry.
- Verify your schema_search_path format; use comma-separated names or quoted identifiers like `"my schema"` to ensure the intended SQL is generated.
- Update sea-orm/sqlx to the latest patch versions in case of a toolchain-specific formatting bug.
- If it reproduces consistently, file an issue with sea-orm including the ConnectOptions used.
- As a workaround, avoid setting schema_search_path and execute `SET search_path` manually after connecting.
Example fix
// before (unquoted schema with special chars)
options.schema_search_path(Some("my schema".to_string()));
// after (explicitly quoted identifier)
options.schema_search_path(Some("\"my schema\"".to_string())); Defensive patterns
Strategy: fallback
Validate before calling
// Validate the schema string before passing it to ConnectOptions:
fn valid_search_path(s: &str) -> bool {
!s.trim().is_empty()
&& s.split(',').all(|p| {
let p = p.trim();
p.starts_with('"') && p.ends_with('"') && p.len() >= 2
|| !p.is_empty() && p.chars().all(|c| c.is_alphanumeric() || c == '_')
})
}
assert!(valid_search_path("app,public")); Try / catch
// This panic is an internal invariant (write! to String); guard the connect call and fall back:
match Database::connect(opts.clone()).await {
Ok(db) => db,
Err(e) => {
// retry without schema_search_path, set it manually
let mut plain = opts;
plain.schema_search_path(None);
let db = Database::connect(plain).await?;
db.execute_unprepared("SET search_path TO app,public").await?;
db
}
} Prevention
- Use well-formed schema identifiers (quoted when containing special characters).
- Keep system memory healthy; this panic is only reachable via allocation failure.
- Keep sea-orm/sqlx updated.
- Prefer the manual SET search_path post-connect pattern if you need tight control.
When it happens
Trigger: Calling sea-orm's Postgres connect (ConnectOptions with `schema_search_path` set) where the `write!` macro appending the schema name to the SQL string returns Err -- practically only on allocation failure, since writing to a String is infallible.
Common situations: Developers encounter this panic site while debugging schema search path configuration (quoted vs unquoted schema names, comma-separated lists); the panic itself is effectively unreachable and usually points to OOM or a Rust/toolchain anomaly rather than a configuration mistake.
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/c22feba93c544dde.
Report an issue: GitHub.