Skip to content

Commit d9fc489

Browse files
committed
feat(config): better errors for mislabeled fields
1 parent c2b9f87 commit d9fc489

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

sqlx-core/src/config/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[cfg_attr(
44
feature = "sqlx-toml",
55
derive(serde::Deserialize),
6-
serde(default, rename_all = "kebab-case")
6+
serde(default, rename_all = "kebab-case", deny_unknown_fields)
77
)]
88
pub struct Config {
99
/// Override the database URL environment variable.

sqlx-core/src/config/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::BTreeMap;
55
#[cfg_attr(
66
feature = "sqlx-toml",
77
derive(serde::Deserialize),
8-
serde(default, rename_all = "kebab-case")
8+
serde(default, rename_all = "kebab-case", deny_unknown_fields)
99
)]
1010
pub struct Config {
1111
/// Specify which crates' types to use when types from multiple crates apply.

sqlx-core/src/config/migrate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::collections::BTreeSet;
1616
#[cfg_attr(
1717
feature = "sqlx-toml",
1818
derive(serde::Deserialize),
19-
serde(default, rename_all = "kebab-case")
19+
serde(default, rename_all = "kebab-case", deny_unknown_fields)
2020
)]
2121
pub struct Config {
2222
/// Specify the names of schemas to create if they don't already exist.

sqlx-core/src/config/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod tests;
4848
#[cfg_attr(
4949
feature = "sqlx-toml",
5050
derive(serde::Deserialize),
51-
serde(default, rename_all = "kebab-case")
51+
serde(default, rename_all = "kebab-case", deny_unknown_fields)
5252
)]
5353
pub struct Config {
5454
/// Configuration shared by multiple components.
@@ -210,6 +210,9 @@ impl Config {
210210
// Only returned if the file exists but the feature is not enabled.
211211
panic!("{e}")
212212
}
213+
Err(ConfigError::Parse { error, path }) => {
214+
panic!("error parsing sqlx config {path:?}: {error}")
215+
}
213216
Err(e) => {
214217
panic!("failed to read sqlx config: {e}")
215218
}

0 commit comments

Comments
 (0)