Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(config): report field path in config type errors

Steven Enamakel66621dd01b03
diff --git a/Cargo.lock b/Cargo.lock
index 722dffebf4..eb562ba8bb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4597,6 +4597,7 @@ dependencies = [
"sentry",
"serde",
"serde_json",
+ "serde_path_to_error",
"sha2 0.10.9",
"starship-battery",
"sysinfo",
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 69c52dcaf1..4bbf521a2e 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -325,6 +325,7 @@ tinycomputer-accessibility = { path = "../../vendor/tinycomputer/crates/tinycomp
tinyskills = { path = "../../vendor/tinyskills/crates/tinyskills" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+serde_path_to_error = "0.1"
# (Removed `html2md` dep. dhat-rs profiling on real Gmail inboxes
# showed `html2md::walk` and `html2md::tables::handle` allocating
# ~894 MB peak heap on a 10 KB HTML input from Otter.ai-style emails
diff --git a/crates/openhuman-core/src/config/schema/load/parse.rs b/crates/openhuman-core/src/config/schema/load/parse.rs
index fec1e0a32c..abd963d2f6 100644
--- a/crates/openhuman-core/src/config/schema/load/parse.rs
+++ b/crates/openhuman-core/src/config/schema/load/parse.rs
@@ -4,8 +4,9 @@
//! `Deserialize` impl in it once per `toml` map-access type (about six), and the
//! tree has well over a hundred types. Parsing into a [`toml::Value`] first and
//! decoding that through [`serde_json::Value`] keeps one decoder instantiation
-//! per type. Syntax errors still carry TOML line and column; a type error keeps
-//! the serde message but not the location.
+//! per type. Syntax errors still carry TOML line and column; a type error names
+//! the dotted field path (`agent.agent_timeout_secs: invalid type: ...`) through
+//! `serde_path_to_error`, though not the line.
use crate::config::Config;
@@ -14,7 +15,10 @@ use crate::config::Config;
pub(crate) fn config_from_toml_str(contents: &str) -> anyhow::Result<Config> {
let document: toml::Value = toml::from_str(contents)?;
let json = serde_json::to_value(document)?;
- Ok(serde_json::from_value(json)?)
+ serde_path_to_error::deserialize(json).map_err(|err| {
+ let path = err.path().to_string();
+ anyhow::anyhow!("{path}: {}", err.into_inner())
+ })
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/config/schema/load/parse_tests.rs b/crates/openhuman-core/src/config/schema/load/parse_tests.rs
index 6c416231c8..e9f0f6ad52 100644
--- a/crates/openhuman-core/src/config/schema/load/parse_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/parse_tests.rs
@@ -39,3 +39,12 @@ fn a_syntax_error_reports_the_toml_location() {
fn a_type_error_is_an_error() {
assert!(config_from_toml_str("default_temperature = \"hot\"").is_err());
}
+
+#[test]
+fn a_type_error_names_the_field_path() {
+ let err = config_from_toml_str("[agent]\nagent_timeout_secs = \"soon\"").unwrap_err();
+ assert!(
+ err.to_string().starts_with("agent.agent_timeout_secs: "),
+ "{err}"
+ );
+}