Merge pull request #16449 from aiongg/engine-precheck-params

Precheck reports the same parameter errors as dispatch
This commit is contained in:
aiongg authored and GitHub committed 2026-11-22 17:17:22 -05:00
commit 755bbdced7
3 files changed
+26 -7

No files matched your search

+1 -5
View File
@@ -1781,11 +1781,7 @@ impl Session {
}
return self.dispatch(&filter, p, background);
}
if id == "file.new" {
crate::document_preset_cmds::validate_new_params(self, &params)?;
}
crate::param_check::check(spec, &params)?;
crate::filters::validate_params(id, &params)?;
self.validate_params(id, spec, &params)?;
// A command that may not run leaves a floating selection floating (#13169): it is refused
// before the piece drops, without a History step. One that may run is checked again
// below, once the piece has dropped, on the pixels and selection it will change.
+10 -2
View File
@@ -59,6 +59,15 @@ impl Session {
self.live_commit = None;
}
/// The per-command value checks `dispatch` and `precheck` share, in the order `dispatch` runs them.
pub(crate) fn validate_params(&self, id: &str, spec: &crate::registry::CommandSpec, params: &Value) -> Result<()> {
if id == "file.new" {
crate::document_preset_cmds::validate_new_params(self, params)?;
}
crate::param_check::check(spec, params)?;
crate::filters::validate_params(id, params)
}
/// Check a call without running it: the command exists, its params have the shape
/// [`Self::execute`] requires (New Layer's fully), and it can run now. For a caller that does
/// something first only when the command will go through: Free Transform applies its box
@@ -71,8 +80,7 @@ impl Session {
if !(params.is_object() || params.is_null()) {
return Err(EngineError::BadParams { cmd: id.to_string(), msg: "params must be a JSON object".into() });
}
crate::param_check::check(spec, params)?;
crate::filters::validate_params(id, params)?;
self.validate_params(id, spec, params)?;
if id == "layer.new.layer" {
crate::new_layer::parse(params)?;
}
+15
View File
@@ -80,3 +80,18 @@ fn precheck_agrees_with_execute() {
}
assert!(disagreements.is_empty(), "{disagreements:#?}");
}
#[test]
fn precheck_reports_file_new_value_errors_like_execute() {
for p in
[json!({"width": 0}), json!({"width": 300_001}), json!({"height": "x"}), json!({"mode": "Bogus"}), json!({"width": 0, "name": 5}), json!({"name": 5})]
{
let pre = Session::new().precheck("file.new", &p).unwrap_err().to_string();
let ran = Session::new().execute("file.new", p.clone()).unwrap_err().to_string();
assert_eq!(pre, ran, "{p}");
}
// Where both checks fail, the value check's message (not the parameter check's) wins, as in dispatch.
let both = Session::new().precheck("file.new", &json!({"width": 0, "name": 5})).unwrap_err().to_string();
assert_eq!(both, "invalid parameters for `file.new`: `name` must be a string");
Session::new().precheck("file.new", &json!({"width": 64, "height": 32})).unwrap();
}