Skip to content

Commit 2510acd

Browse files
committed
better errors on invalid database connection strings
1 parent 031e2c4 commit 2510acd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.19.1 (2024-02-28)
44
- **SECURITY**: fixes users being able to re-run migrations by visiting `/sqlpage/migrations/NNNN_name.sql` pages. If you are using sqlpage migrations, your migrations are not idempotent, and you use the default SQLPAGE_WEB_ROOT (`./`) and `SQLPAGE_CONFIGURATION_DIRECTORY` (`./sqlpage/`), you should upgrade to this version as soon as possible. If you are using a custom `SQLPAGE_WEB_ROOT` or `SQLPAGE_CONFIGURATION_DIRECTORY` or your migrations are idempotent, you can upgrade at your convenience.
5+
- Better error messages on invalid database connection strings. SQLPage now displays a more precise and useful message when an error occurs instead of a "panic" message.
56

67
## 0.19.0 (2024-02-25)
78

src/webserver/database/connect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::time::Duration;
22

33
use super::Database;
44
use crate::{app_config::AppConfig, ON_CONNECT_FILE};
5+
use anyhow::Context;
56
use sqlx::{
67
any::{Any, AnyConnectOptions, AnyKind},
78
pool::PoolOptions,
@@ -13,7 +14,9 @@ impl Database {
1314
pub async fn init(config: &AppConfig) -> anyhow::Result<Self> {
1415
let database_url = &config.database_url;
1516
let mut connect_options: AnyConnectOptions =
16-
database_url.parse().expect("Invalid database URL");
17+
database_url
18+
.parse()
19+
.with_context(|| format!("{database_url:?} is not a valid database URL"))?;
1720
connect_options.log_statements(log::LevelFilter::Trace);
1821
connect_options.log_slow_statements(
1922
log::LevelFilter::Warn,

0 commit comments

Comments
 (0)