mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Stop recorded parents after Batch file failures
This commit is contained in:
1 parent
6e2ae5f82b
commit
c60fc81fc3
4 files changed
+36
-11
No files matched your search
@@ -512,6 +512,15 @@ pub fn restore_recording(s: &mut Session, idx: usize, action: &str, from: usize)
|
||||
/// Nested playback returns a structured failure even though the command itself succeeded.
|
||||
/// Promote it to the caller's failed step so no later parent steps run after a child fails.
|
||||
pub fn nested_failure(id: &str, value: &Value) -> Option<String> {
|
||||
// Batch keeps per-file results for direct callers, but a failed recorded Batch step stops its parent.
|
||||
if id == "file.automate.batch" {
|
||||
let failure = value.get("errors")?.as_array()?.first()?;
|
||||
return Some(format!(
|
||||
"Batch failed for {}: {}",
|
||||
failure.get("file").and_then(Value::as_str).unwrap_or("an input"),
|
||||
failure.get("error").and_then(Value::as_str).unwrap_or("unknown error")
|
||||
));
|
||||
}
|
||||
(id == "actions.play" || id == "actions.conditional").then(|| value.get("failed")).flatten().map(|failure| {
|
||||
format!(
|
||||
"action `{}` step {} failed: {}",
|
||||
|
||||
@@ -138,14 +138,17 @@ fn run_steps(s: &mut Session, steps: &[(String, Value)]) -> Vec<Value> {
|
||||
break;
|
||||
}
|
||||
match s.execute(id, params.clone()) {
|
||||
// A called action reports a failed step inside an `Ok`; it stops the script too.
|
||||
Ok(r) => match crate::actions_cmds::nested_failure(id, &r).or_else(|| nested_script_failure(id, &r)) {
|
||||
Some(error) => {
|
||||
results.push(json!({"command": id, "result": r, "error": error}));
|
||||
break;
|
||||
Ok(r) => {
|
||||
// Direct Batch calls report file errors successfully to scripts. Called actions still fail the script.
|
||||
let action_failure = if id == "file.automate.batch" { None } else { crate::actions_cmds::nested_failure(id, &r) };
|
||||
match action_failure.or_else(|| nested_script_failure(id, &r)) {
|
||||
Some(error) => {
|
||||
results.push(json!({"command": id, "result": r, "error": error}));
|
||||
break;
|
||||
}
|
||||
None => results.push(json!({"command": id, "result": r})),
|
||||
}
|
||||
None => results.push(json!({"command": id, "result": r})),
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
results.push(json!({"command": id, "error": e.to_string()}));
|
||||
break;
|
||||
|
||||
@@ -109,15 +109,25 @@ fn batch_recorded_stop_for_errors_retains_earlier_outputs_and_stops_before_later
|
||||
let p = json!({"input":dir,"output":output,"action":"Child","set":"S","stopOnError":true,
|
||||
"includeSubfolders":false,"overrideSaveAs":false,"flatOutput":true,
|
||||
"namingComponents":[{"component":"name"},{"component":"extension"}]});
|
||||
let driver = crate::actions_cmds::Action::new("Driver", vec![("file.automate.batch".into(), p)]);
|
||||
let sentinel = json!({"width":7,"height":9});
|
||||
let driver = crate::actions_cmds::Action::new("Driver", vec![("file.automate.batch".into(), p.clone()), ("file.new".into(), sentinel.clone())]);
|
||||
let (bytes, skipped) = crate::atn_cmds::export("S", &[&driver], &[], false).unwrap();
|
||||
assert!(skipped.is_empty());
|
||||
s.actions.list.extend(crate::atn_cmds::import(&bytes).unwrap().actions);
|
||||
let imported = crate::atn_cmds::import(&bytes).unwrap();
|
||||
assert_eq!(imported.actions[0].steps[1].0, "file.new", "the after-Batch sentinel must be replayable");
|
||||
s.actions.list.extend(imported.actions);
|
||||
let result = s.execute("actions.play", json!({"action":"Driver"})).unwrap();
|
||||
assert_eq!(result["ran"], 1, "{result}");
|
||||
assert!(result.get("failed").is_none(), "{result}");
|
||||
assert_eq!(result["ran"], 0, "{result}");
|
||||
assert_eq!(result["failed"]["id"], "file.automate.batch");
|
||||
assert!(result["failed"]["error"].as_str().unwrap().contains("b.png"), "{result}");
|
||||
assert!(s.documents().is_empty(), "the command after the failed Batch must not run");
|
||||
assert!(std::path::Path::new(&join(&output, "a.png")).is_file());
|
||||
assert!(!std::path::Path::new(&join(&output, "c.png")).exists());
|
||||
// The measured scripting API reports success for the same stopped Batch and continues the script.
|
||||
let result = s.execute("file.scripts.browse", json!({"steps":[["file.automate.batch",p],["file.new",sentinel]]})).unwrap();
|
||||
assert_eq!(result["ok"], true, "{result}");
|
||||
assert_eq!(result["results"][0]["result"]["errors"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(s.documents().len(), 1, "the direct script caller still runs its next command");
|
||||
let invalid_output = join(&dir, "invalid");
|
||||
let err = s.execute("file.automate.batch", json!({"input":[first],"output":invalid_output,"steps":[],"stopOnError":"true"})).unwrap_err();
|
||||
assert!(err.to_string().contains("stopOnError"), "{err}");
|
||||
|
||||
@@ -258,6 +258,9 @@ Recorded folder steps without an error log set `stopOnError`: the first failed
|
||||
input is reported, earlier outputs stay saved and later inputs are not processed.
|
||||
The native command still continues by default. That continuing mode cannot be
|
||||
exported as a no-log Batch step, which would change its error policy.
|
||||
Any reported file error fails a recorded Batch step, so its parent action does
|
||||
not run later steps. A direct scripting call still returns the collected file
|
||||
results successfully, as measured in the reference application.
|
||||
|
||||
This maps supported text-path folder forms. Alias bytes, open-document sources,
|
||||
Save and Close, error logs and enabled Open/dialog overrides remain preserved
|
||||
|
||||
Reference in new issue
Block a user