{"record":{"id":"c22feba93c544dde","repo":"SeaQL/sea-orm","slug":"infallible-c22feb","errorCode":null,"errorMessage":"Infallible","messagePattern":"Infallible","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/driver/sqlx_postgres.rs","lineNumber":101,"sourceCode":"            }\n        }\n\n        if let Some(application_name) = &options.application_name {\n            sqlx_opts = sqlx_opts.application_name(application_name);\n        }\n\n        if let Some(timeout) = options.statement_timeout {\n            sqlx_opts = sqlx_opts.options([(\"statement_timeout\", timeout.as_millis().to_string())]);\n        }\n\n        if let Some(f) = &options.pg_opts_fn {\n            sqlx_opts = f(sqlx_opts);\n        }\n\n        let set_search_path_sql = options.schema_search_path.as_ref().map(|schema| {\n            let mut string = \"SET search_path = \".to_owned();\n            if schema.starts_with('\"') {\n                write!(&mut string, \"{schema}\").expect(\"Infallible\");\n            } else {\n                for (i, schema) in schema.split(',').enumerate() {\n                    if i > 0 {\n                        write!(&mut string, \",\").expect(\"Infallible\");\n                    }\n                    if schema.starts_with('\"') {\n                        write!(&mut string, \"{schema}\").expect(\"Infallible\");\n                    } else {\n                        write!(&mut string, \"\\\"{schema}\\\"\").expect(\"Infallible\");\n                    }\n                }\n            }\n            string\n        });\n\n        let lazy = options.connect_lazy;\n        let after_connect = options.after_connect.clone();\n        let pg_pool_opts_fn = options.pg_pool_opts_fn.clone();","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (unquoted schema with special chars)\noptions.schema_search_path(Some(\"my schema\".to_string()));\n\n// after (explicitly quoted identifier)\noptions.schema_search_path(Some(\"\\\"my schema\\\"\".to_string()));","handlingStrategy":"fallback","validationCode":"// Validate the schema string before passing it to ConnectOptions:\nfn valid_search_path(s: &str) -> bool {\n    !s.trim().is_empty()\n        && s.split(',').all(|p| {\n            let p = p.trim();\n            p.starts_with('\"') && p.ends_with('\"') && p.len() >= 2\n                || !p.is_empty() && p.chars().all(|c| c.is_alphanumeric() || c == '_')\n        })\n}\nassert!(valid_search_path(\"app,public\"));","typeGuard":null,"tryCatchPattern":"// This panic is an internal invariant (write! to String); guard the connect call and fall back:\nmatch Database::connect(opts.clone()).await {\n    Ok(db) => db,\n    Err(e) => {\n        // retry without schema_search_path, set it manually\n        let mut plain = opts;\n        plain.schema_search_path(None);\n        let db = Database::connect(plain).await?;\n        db.execute_unprepared(\"SET search_path TO app,public\").await?;\n        db\n    }\n}","preventionTips":["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."],"tags":["postgres","connect","internal-invariant","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}