feat(config): better errors for mislabeled fields

This commit is contained in:
Austin Bonander 2025-02-21 15:52:27 -08:00
parent c2b9f87e31
commit d9fc4899ad
4 changed files with 7 additions and 4 deletions

View File

@ -3,7 +3,7 @@
#[cfg_attr(
feature = "sqlx-toml",
derive(serde::Deserialize),
serde(default, rename_all = "kebab-case")
serde(default, rename_all = "kebab-case", deny_unknown_fields)
)]
pub struct Config {
/// Override the database URL environment variable.

View File

@ -5,7 +5,7 @@ use std::collections::BTreeMap;
#[cfg_attr(
feature = "sqlx-toml",
derive(serde::Deserialize),
serde(default, rename_all = "kebab-case")
serde(default, rename_all = "kebab-case", deny_unknown_fields)
)]
pub struct Config {
/// Specify which crates' types to use when types from multiple crates apply.

View File

@ -16,7 +16,7 @@ use std::collections::BTreeSet;
#[cfg_attr(
feature = "sqlx-toml",
derive(serde::Deserialize),
serde(default, rename_all = "kebab-case")
serde(default, rename_all = "kebab-case", deny_unknown_fields)
)]
pub struct Config {
/// Specify the names of schemas to create if they don't already exist.

View File

@ -48,7 +48,7 @@ mod tests;
#[cfg_attr(
feature = "sqlx-toml",
derive(serde::Deserialize),
serde(default, rename_all = "kebab-case")
serde(default, rename_all = "kebab-case", deny_unknown_fields)
)]
pub struct Config {
/// Configuration shared by multiple components.
@ -210,6 +210,9 @@ impl Config {
// Only returned if the file exists but the feature is not enabled.
panic!("{e}")
}
Err(ConfigError::Parse { error, path }) => {
panic!("error parsing sqlx config {path:?}: {error}")
}
Err(e) => {
panic!("failed to read sqlx config: {e}")
}