Skip to content

Commit

Permalink
better errors on invalid database connection strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Feb 28, 2024
1 parent 031e2c4 commit 2510acd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.19.1 (2024-02-28)
- **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.
- 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.

## 0.19.0 (2024-02-25)

Expand Down
5 changes: 4 additions & 1 deletion src/webserver/database/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::time::Duration;

use super::Database;
use crate::{app_config::AppConfig, ON_CONNECT_FILE};
use anyhow::Context;
use sqlx::{
any::{Any, AnyConnectOptions, AnyKind},
pool::PoolOptions,
Expand All @@ -13,7 +14,9 @@ impl Database {
pub async fn init(config: &AppConfig) -> anyhow::Result<Self> {
let database_url = &config.database_url;
let mut connect_options: AnyConnectOptions =
database_url.parse().expect("Invalid database URL");
database_url
.parse()
.with_context(|| format!("{database_url:?} is not a valid database URL"))?;
connect_options.log_statements(log::LevelFilter::Trace);
connect_options.log_slow_statements(
log::LevelFilter::Warn,
Expand Down

0 comments on commit 2510acd

Please sign in to comment.