{"record":{"id":"b41107f8aa25332e","repo":"SeaQL/sea-orm","slug":"fail-to-parse-database-url-b41107","errorCode":null,"errorMessage":"Fail to parse database URL","messagePattern":"Fail to parse database URL","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/database/db_connection.rs","lineNumber":870,"sourceCode":"    /// Panics if [DbConn] is not a SQLite connection.\n    #[cfg(feature = \"sqlx-sqlite\")]\n    pub fn get_sqlite_connection_pool(&self) -> &sqlx::SqlitePool {\n        match &self.inner {\n            DatabaseConnectionType::SqlxSqlitePoolConnection(conn) => &conn.pool,\n            _ => panic!(\"Not SQLite Connection\"),\n        }\n    }\n}\n\nimpl DbBackend {\n    /// Check if the URI is the same as the specified database backend.\n    /// Returns true if they match.\n    ///\n    /// # Panics\n    ///\n    /// Panics if `base_url` cannot be parsed as `Url`.\n    pub fn is_prefix_of(self, base_url: &str) -> bool {\n        let base_url_parsed = Url::parse(base_url).expect(\"Fail to parse database URL\");\n        match self {\n            Self::Postgres => {\n                base_url_parsed.scheme() == \"postgres\" || base_url_parsed.scheme() == \"postgresql\"\n            }\n            Self::MySql => base_url_parsed.scheme() == \"mysql\",\n            Self::Sqlite => base_url_parsed.scheme() == \"sqlite\",\n        }\n    }\n\n    /// Build an SQL [Statement]\n    pub fn build<S>(&self, statement: &S) -> Statement\n    where\n        S: StatementBuilder,\n    {\n        statement.build(self)\n    }\n\n    /// Check if the database supports `RETURNING` syntax on insert and update","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/database/db_connection.rs#L852-L888","documentation":"`DbBackend::is_prefix_of` parses the given `base_url` with `Url::parse(...).expect(\"Fail to parse database URL\")` to compare its scheme against the backend. If the string is not a valid URL, the expect panics. The function is also used by `assert_database_connection_traits`, so invalid connection strings surface as a panic rather than a returned error.","triggerScenarios":"Calling `is_prefix_of` / `assert_database_connection_traits` with a database URL that is not parseable by the `url` crate — missing scheme (`localhost/db`), spaces, stray characters, or a malformed host.","commonSituations":"DATABASE_URL env var set from a .env file with quotes or unencoded special characters; forgetting the `postgres://`, `mysql://`, or `sqlite://` prefix; typos like `postgresql//host`.","solutions":["Validate the URL before calling: `Url::parse(db_url)?` in your own code and surface a friendly error.","Ensure the URL starts with a supported scheme: postgres://, postgresql://, mysql://, or sqlite://.","Percent-encode special characters in passwords (e.g. @ -> %40) inside the connection string."],"exampleFix":"// before\nassert_database_connection_traits(DbBackend::MySql, std::env::var(\"DATABASE_URL\")?);\n// after\nlet url = std::env::var(\"DATABASE_URL\")?;\nurl::Url::parse(&url).map_err(|_| anyhow!(\"Invalid DATABASE_URL: {url}\"))?; // scheme must be mysql://\nassert_database_connection_traits(DbBackend::MySql, &url);","handlingStrategy":"validation","validationCode":"use url::Url;\nfn validate_db_url(u: &str) -> Result<(), String> {\n    let parsed = Url::parse(u).map_err(|e| format!(\"invalid DATABASE_URL '{u}': {e}\"))?;\n    match parsed.scheme() {\n        \"postgres\" | \"postgresql\" | \"mysql\" | \"sqlite\" => Ok(()),\n        s => Err(format!(\"unsupported scheme '{s}'\")),\n    }\n}","typeGuard":"fn is_valid_db_url(s: &str) -> bool { url::Url::parse(s).is_ok() }","tryCatchPattern":null,"preventionTips":["Always include an explicit scheme (postgres://, mysql://, sqlite://) in connection strings.","Percent-encode special characters in passwords.","Validate DATABASE_URL at startup, before any library call parses it."],"tags":["panic","url","database-url","config"],"backgroundTag":"invalid-url-format","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}