fix: config file parse errors not reported as missing DATABASE_URL

This commit is contained in:
2026-10-25 21:02:35 +01:00
parent 8bdf55cfe1
commit 1f724bb064
4 changed files with 16 additions and 50 deletions

View File

@@ -98,6 +98,9 @@ pub fn load() -> Result<AppConfig, ConfigError> {
let figment = Figment::new().merge(Toml::file(path)).merge(LegacyEnv);
figment
.data()
.map_err(|e| ConfigError::Unreadable(Box::new(e)))?;
if figment.find_value("database.url").is_err() {
return Err(ConfigError::Missing("DATABASE_URL"));
}

View File

@@ -377,3 +377,15 @@ fn secure_cookies_and_image_conversion_accept_true_only() {
Ok(())
});
}
#[test]
fn malformed_config_file_reports_the_file_not_a_missing_database_url() {
Jail::expect_with(|jail| {
jail_with(jail, &[]);
jail.create_file("config.toml", "[server\nport = = 1\n")?;
let err = load().expect_err("config.toml is malformed");
assert!(matches!(err, ConfigError::Unreadable(_)), "{err}");
assert!(!err.to_string().contains("DATABASE_URL"), "{err}");
Ok(())
});
}