Preserve CLI run continuation after direct Batch file errors

This commit is contained in:
yoriswind committed 2026-11-04 11:15:56 -08:00
1 parent 3edffb77ec
commit 1457ea39ba
2 files changed
+42 -1

No files matched your search

+3 -1
View File
@@ -100,7 +100,9 @@ pub(crate) fn run_cmds(a: &RunArgs, out: &mut dyn Write, err: &mut dyn Write) ->
continue;
}
let r = h.command_run(&id, params).map_err(|source| CliError::Command { id: id.clone(), source })?;
if let Some(message) = photocraft_engine::actions_cmds::nested_failure(&id, &r) {
// A direct Batch reports per-file errors and continues, as in Scripts; failed
// action or script calls still stop the command list before export.
if let Some(message) = photocraft_engine::actions_cmds::nested_failure(&id, &r).filter(|_| id != "file.automate.batch") {
return Err(CliError::NestedFailure { id, message });
}
let new_warnings: Vec<String> =
+39
View File
@@ -363,6 +363,45 @@ fn run_stops_after_failed_action_without_exporting() {
std::fs::remove_dir_all(d).unwrap();
}
/// A direct Batch keeps its partial result without preventing later commands or export.
#[test]
fn run_continues_after_batch_file_errors_and_keeps_partial_results() {
let d = tmp("run-partial-batch");
let good = d.join("good.png");
let bad = d.join("bad.png");
let batch_out = d.join("batch");
let caller_out = d.join("caller.pcraft");
write_png(&good, 6, 4, 3);
std::fs::write(&bad, b"not a PNG").unwrap();
let params = json!({"input":[good,bad],"output":batch_out,"format":"pcraft","steps":[
["layer.renameLayer",{"name":"Batch output"}]
]})
.to_string();
let stdout = ok(bin()
.args(["run", "--new", r#"{"width":8,"height":8}"#])
.args(["--cmd", "file.automate.batch", "--params", &params])
.args(["--cmd", "layer.new.layer", "--params", r#"{"name":"After batch"}"#])
.args(["--cmd", "document.inspect", "--out"])
.arg(&caller_out))
.stdout;
let rows: Vec<Value> = stdout.lines().map(|line| serde_json::from_str(line).unwrap()).collect();
assert_eq!(rows.len(), 3);
assert_eq!(rows[0]["command"], "file.automate.batch");
let result = &rows[0]["result"];
assert_eq!(result["files"], json!([batch_out.join("good.pcraft")]));
assert_eq!(result["errors"].as_array().unwrap().len(), 1);
assert_eq!(result["errors"][0]["file"], json!(bad));
assert!(result["errors"][0]["error"].as_str().is_some_and(|message| !message.is_empty()));
assert!(batch_out.join("good.pcraft").is_file());
assert!(!batch_out.join("bad.pcraft").exists());
assert_eq!(rows[2]["command"], "document.inspect");
assert!(rows[2]["result"]["layers"].as_array().unwrap().iter().any(|layer| layer["name"] == "After batch"));
assert!(caller_out.is_file());
let saved: Value = serde_json::from_str(&ok(bin().arg("info").arg(&caller_out)).stdout).unwrap();
assert!(saved["layers"].as_array().unwrap().iter().any(|layer| layer["name"] == "After batch"));
std::fs::remove_dir_all(d).unwrap();
}
#[test]
fn run_continues_after_successful_action_and_exports() {
let d = tmp("run-successful-action");