forked from 1b-agent/fieldcraft-upstream
Engine: a parameter error carries its key and problem (EngineError::Param)
A form can show the problem beside the field it is about. The message still names the key, as before, for agents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
1 parent
8df4ea040c
commit
9dcbb9c9a6
14 files changed
+60
-49
No files matched your search
@@ -134,7 +134,7 @@ fn cap<T: Copy + TryInto<u64> + TryFrom<u64> + std::fmt::Display>(p: &Value, key
|
||||
.as_u64()
|
||||
.filter(|n| (1..=most).contains(n))
|
||||
.and_then(|n| T::try_from(n).ok())
|
||||
.ok_or_else(|| EngineError::Params(format!("`{key}` must be a whole number from 1 to {default}"))),
|
||||
.ok_or_else(|| EngineError::param(key, format!("must be a whole number from 1 to {default}"))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ fn history(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let h = &r.history;
|
||||
let samples = h.time.len();
|
||||
let every = match opt::<u64>(p, "every")? {
|
||||
Some(0) => return Err(EngineError::Params("`every` must be at least 1".into())),
|
||||
Some(0) => return Err(EngineError::param("every", "must be at least 1")),
|
||||
Some(k) => usize::try_from(k).unwrap_or(usize::MAX),
|
||||
None => samples.div_ceil(MAX_HISTORY_SAMPLES).max(1),
|
||||
};
|
||||
@@ -541,7 +541,7 @@ fn probe_fluid(r: &FluidResult, p: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
fn probe(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let step = opt::<String>(p, "step")?.ok_or_else(|| EngineError::Params("`step` is required".into()))?;
|
||||
let step = opt::<String>(p, "step")?.ok_or_else(|| EngineError::param("step", "is required"))?;
|
||||
let result = s.result(&step).ok_or_else(|| {
|
||||
EngineError::Params(if s.latest_result(&step).is_some() {
|
||||
format!("the result of step `{step}` is stale (the model changed since it was solved); solve it again")
|
||||
|
||||
Reference in new issue
Block a user