From c68d0a1925637d7caa6d26ef85202d93e9535a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Tue, 3 Nov 2026 22:03:59 +0100 Subject: [PATCH 1/5] fix(ui): a save that failed some Image Assets reports which outputs (#11117) --- crates/ui-egui/src/app/files.rs | 87 +++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index de9c6dc147..ca41e02564 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -599,6 +599,8 @@ impl PhotocraftApp { } fn saved_inner(&mut self, doc: DocId, revision: u64, path: &str, warnings: &[String], copy: bool, kind: SaveKind) { + // Per-output Image Assets failures from the after-save hook, reported with this save (#11117). + let mut asset_errors: Vec = Vec::new(); // Automation: only a layered save becomes the document's file; a flat one is a // copy, as in the headless server (#2579). let (hooks, arm) = match kind { @@ -628,11 +630,21 @@ impl PhotocraftApp { && let Some(i) = app.session.active_index() && let Some(r) = photocraft_engine::automate_cmds::document_saved(&mut app.session, i) { - let template = "Saved {path}; image assets: {n} in {dir}"; - app.ui.status = crate::i18n::fmt( - tl!(template), - &[("path", path), ("n", &r["files"].as_array().map_or(0, Vec::len).to_string()), ("dir", r["dir"].as_str().unwrap_or(""))], - ); + let n = r["files"].as_array().map_or(0, Vec::len).to_string(); + let dir = r["dir"].as_str().unwrap_or(""); + asset_errors = r["errors"] + .as_array() + .into_iter() + .flatten() + .map(|e| format!("{}: {}", e["asset"].as_str().unwrap_or("an asset"), e["error"].as_str().unwrap_or("the export failed"))) + .collect(); + let template = if asset_errors.is_empty() { + "Saved {path}; image assets: {n} in {dir}" + } else { + "Saved {path}; image assets: {n} in {dir} ({e} failed)" + }; + let e = asset_errors.len().to_string(); + app.ui.status = crate::i18n::fmt(tl!(template), &[("path", path), ("n", &n), ("dir", dir), ("e", &e)]); } Ok(()) }); @@ -648,6 +660,18 @@ impl PhotocraftApp { self.ui.status_error = false; let what = crate::i18n::fmt(tl!("Saved {name}"), &[("name", file_open::display_name(path).as_str())]); notices::io_warnings(self, &what, warnings); + // #11117: a successful save whose Image Assets partially failed must say which outputs + // did not land: the status line shows the first, a notice lists them all. + if !asset_errors.is_empty() { + let n = asset_errors.len(); + let title = crate::i18n::fmt( + &crate::i18n::trn(crate::i18n::current(), n as u64, "Image Assets: {n} output failed", "Image Assets: {n} outputs failed"), + &[("n", &n.to_string())], + ); + self.ui.status = if n == 1 { format!("{title}: {}", asset_errors[0]) } else { format!("{title}: {} …", asset_errors[0]) }; + self.ui.status_error = true; + notices::post(self, title, asset_errors, true, None); + } self.sync_views(); } @@ -810,3 +834,56 @@ impl PhotocraftApp { f } } + +#[cfg(test)] +mod tests { + use super::*; + + /// #11117: when Image Assets partially failed after a successful user save, the failures + /// were dropped with the hook result and the status only counted the assets that worked. + #[test] + fn a_user_save_reports_image_assets_outputs_that_failed() { + let unique = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_nanos()).unwrap_or(0); + let root = std::env::temp_dir().join(format!("photocraft-11117-{}-{unique}", std::process::id())); + let assets = root.join("probe-assets"); + std::fs::create_dir_all(&assets).unwrap(); + // `blocked` is a regular file, so the `blocked/fail.png` asset cannot create its folder; + // `good.png` stays writable. No permissions or artificial results are involved. + std::fs::write(assets.join("blocked"), "not a folder").unwrap(); + let path = root.join("probe.psd").to_string_lossy().into_owned(); + + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.session.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); + let doc = app.session.active().unwrap().doc.id; + for name in ["good.png", "blocked/fail.png"] { + let id = app.session.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); + // A layer with no pixels is "the layer is empty" before its path is even looked at, + // so both layers carry a painted pixel and only the blocked folder can fail. + app.session.execute("edit.fill", json!({"contents": "color", "color": "#808080"})).unwrap(); + app.session.execute("layer.renameLayer", json!({"layer": id, "name": name})).unwrap(); + } + app.session.prefs.edit(|p| p.plug_ins.generator_enabled = true); + app.session.file_menu.image_assets.push(doc); + + let revision = app.session.active().unwrap().revision; + app.saved(doc, revision, &path, &[], false); + + assert_eq!(app.session.active().unwrap().path.as_deref(), Some(path.as_str()), "the document save itself succeeded"); + assert!(assets.join("good.png").is_file(), "the good asset was exported"); + let notice = app.ui.notices.iter().find(|notice| notice.error).expect("the failed asset is reported as an error notice"); + assert_eq!(notice.title, "Image Assets: 1 output failed"); + assert_eq!(notice.lines.len(), 1, "{:?}", notice.lines); + assert!(notice.lines[0].starts_with("blocked/fail.png: asset path"), "{:?}", notice.lines[0]); + assert!(app.ui.status_error, "the status line carries the failure"); + assert!(app.ui.status.starts_with(¬ice.title) && app.ui.status.contains("blocked/fail.png"), "{}", app.ui.status); + // A clean generation afterwards reports the success line with no error notice (#11079 control). + app.ui.notices.clear(); + std::fs::remove_file(assets.join("blocked")).unwrap(); + let revision = app.session.active().unwrap().revision; + app.saved(doc, revision, &path, &[], false); + assert!(app.ui.notices.iter().all(|notice| !notice.error), "no notice when every asset went out"); + assert!(!app.ui.status_error); + assert!(app.ui.status.contains("image assets: 2 in"), "{}", app.ui.status); + let _ = std::fs::remove_dir_all(&root); + } +} From 7ad4797c2ea171780b5fb5ec694c54fa4ba1499e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Tue, 3 Nov 2026 22:50:47 +0100 Subject: [PATCH 2/5] fix(ui): the Image Assets failure names the saved document Review follow-up: the failure status and notice keep the Saved file name, so with several documents or a late background save the user sees which one saved fine and whose assets failed. --- crates/ui-egui/src/app/files.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index ca41e02564..7e69e7ef70 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -661,12 +661,13 @@ impl PhotocraftApp { let what = crate::i18n::fmt(tl!("Saved {name}"), &[("name", file_open::display_name(path).as_str())]); notices::io_warnings(self, &what, warnings); // #11117: a successful save whose Image Assets partially failed must say which outputs - // did not land: the status line shows the first, a notice lists them all. + // did not land, and of which document: the status line shows the first failure under the + // saved file's name, a notice lists them all. if !asset_errors.is_empty() { let n = asset_errors.len(); let title = crate::i18n::fmt( - &crate::i18n::trn(crate::i18n::current(), n as u64, "Image Assets: {n} output failed", "Image Assets: {n} outputs failed"), - &[("n", &n.to_string())], + &crate::i18n::trn(crate::i18n::current(), n as u64, "{what}: {n} Image Assets output failed", "{what}: {n} Image Assets outputs failed"), + &[("what", &what), ("n", &n.to_string())], ); self.ui.status = if n == 1 { format!("{title}: {}", asset_errors[0]) } else { format!("{title}: {} …", asset_errors[0]) }; self.ui.status_error = true; @@ -871,7 +872,7 @@ mod tests { assert_eq!(app.session.active().unwrap().path.as_deref(), Some(path.as_str()), "the document save itself succeeded"); assert!(assets.join("good.png").is_file(), "the good asset was exported"); let notice = app.ui.notices.iter().find(|notice| notice.error).expect("the failed asset is reported as an error notice"); - assert_eq!(notice.title, "Image Assets: 1 output failed"); + assert_eq!(notice.title, "Saved probe.psd: 1 Image Assets output failed", "the failure names the saved document"); assert_eq!(notice.lines.len(), 1, "{:?}", notice.lines); assert!(notice.lines[0].starts_with("blocked/fail.png: asset path"), "{:?}", notice.lines[0]); assert!(app.ui.status_error, "the status line carries the failure"); From 0122a97a40549c83da797f6c9a76076464049015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Tue, 3 Nov 2026 23:37:50 +0100 Subject: [PATCH 3/5] fix(ui): the Image Assets failure keeps the full path and what did go out Review follow-up on the Image Assets PR: the notice title carries the full saved path so same-named documents in different folders stay distinguishable, and the status line keeps the success count and assets folder alongside the first failure. --- crates/ui-egui/src/app/files.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index 7e69e7ef70..ccf278d637 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -601,6 +601,9 @@ impl PhotocraftApp { fn saved_inner(&mut self, doc: DocId, revision: u64, path: &str, warnings: &[String], copy: bool, kind: SaveKind) { // Per-output Image Assets failures from the after-save hook, reported with this save (#11117). let mut asset_errors: Vec = Vec::new(); + // The successful outputs and their folder, kept for the partial-failure status line. + let mut asset_ok = 0usize; + let mut asset_dir = String::new(); // Automation: only a layered save becomes the document's file; a flat one is a // copy, as in the headless server (#2579). let (hooks, arm) = match kind { @@ -630,7 +633,10 @@ impl PhotocraftApp { && let Some(i) = app.session.active_index() && let Some(r) = photocraft_engine::automate_cmds::document_saved(&mut app.session, i) { - let n = r["files"].as_array().map_or(0, Vec::len).to_string(); + let files = r["files"].as_array().map_or(0, Vec::len); + asset_ok = files; + asset_dir = r["dir"].as_str().unwrap_or("").to_string(); + let n = files.to_string(); let dir = r["dir"].as_str().unwrap_or(""); asset_errors = r["errors"] .as_array() @@ -661,15 +667,17 @@ impl PhotocraftApp { let what = crate::i18n::fmt(tl!("Saved {name}"), &[("name", file_open::display_name(path).as_str())]); notices::io_warnings(self, &what, warnings); // #11117: a successful save whose Image Assets partially failed must say which outputs - // did not land, and of which document: the status line shows the first failure under the - // saved file's name, a notice lists them all. + // did not land, and of which document: the status keeps the full saved path (same-named + // documents only differ by their folder) and what did go out, the notice lists every failure. if !asset_errors.is_empty() { - let n = asset_errors.len(); + let e = asset_errors.len(); + let full = crate::i18n::fmt(tl!("Saved {name}"), &[("name", path)]); let title = crate::i18n::fmt( - &crate::i18n::trn(crate::i18n::current(), n as u64, "{what}: {n} Image Assets output failed", "{what}: {n} Image Assets outputs failed"), - &[("what", &what), ("n", &n.to_string())], + &crate::i18n::trn(crate::i18n::current(), e as u64, "{what}: {n} Image Assets output failed", "{what}: {n} Image Assets outputs failed"), + &[("what", &full), ("n", &e.to_string())], ); - self.ui.status = if n == 1 { format!("{title}: {}", asset_errors[0]) } else { format!("{title}: {} …", asset_errors[0]) }; + let written = crate::i18n::fmt(tl!("{ok} written to {dir}"), &[("ok", &asset_ok.to_string()), ("dir", &asset_dir)]); + self.ui.status = format!("{title} ({written}): {}", asset_errors[0]); self.ui.status_error = true; notices::post(self, title, asset_errors, true, None); } @@ -872,11 +880,16 @@ mod tests { assert_eq!(app.session.active().unwrap().path.as_deref(), Some(path.as_str()), "the document save itself succeeded"); assert!(assets.join("good.png").is_file(), "the good asset was exported"); let notice = app.ui.notices.iter().find(|notice| notice.error).expect("the failed asset is reported as an error notice"); - assert_eq!(notice.title, "Saved probe.psd: 1 Image Assets output failed", "the failure names the saved document"); + assert_eq!(notice.title, format!("Saved {path}: 1 Image Assets output failed"), "the failure names the saved document by its full path"); assert_eq!(notice.lines.len(), 1, "{:?}", notice.lines); assert!(notice.lines[0].starts_with("blocked/fail.png: asset path"), "{:?}", notice.lines[0]); assert!(app.ui.status_error, "the status line carries the failure"); - assert!(app.ui.status.starts_with(¬ice.title) && app.ui.status.contains("blocked/fail.png"), "{}", app.ui.status); + assert!(app.ui.status.starts_with(¬ice.title), "{}", app.ui.status); + assert!( + app.ui.status.contains("1 written to") && app.ui.status.contains("blocked/fail.png"), + "the status keeps the success count, folder and first failure: {}", + app.ui.status + ); // A clean generation afterwards reports the success line with no error notice (#11079 control). app.ui.notices.clear(); std::fs::remove_file(assets.join("blocked")).unwrap(); From 9fdcbf93c23bf0b5268f4f7eb68587b86124393d Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 13:48:59 +0100 Subject: [PATCH 4/5] test: cover asset failure after save script shifts tabs --- crates/ui-egui/src/app/files.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index 426fc36a6d..7fcc1c49a5 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -859,6 +859,8 @@ mod tests { let path = root.join("probe.psd").to_string_lossy().into_owned(); let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + // A save script closes this earlier tab, shifting the saved document's index. + app.session.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); app.session.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let doc = app.session.active().unwrap().doc.id; for name in ["good.png", "blocked/fail.png"] { @@ -870,10 +872,14 @@ mod tests { } app.session.prefs.edit(|p| p.plug_ins.generator_enabled = true); app.session.file_menu.image_assets.push(doc); + app.session.execute("file.scripts.scriptEventsManager", json!({"enabled": true, "add": {"event": "saveDocument", "steps": [["file.close", {"document": 0}]]}})).unwrap(); let revision = app.session.active().unwrap().revision; app.saved(doc, revision, &path, &[], false); + assert_eq!(app.session.documents().len(), 1); + assert_eq!(app.session.active().unwrap().doc.id, doc); + assert_eq!(app.session.active().unwrap().path.as_deref(), Some(path.as_str()), "the document save itself succeeded"); assert!(assets.join("good.png").is_file(), "the good asset was exported"); let notice = app.ui.notices.iter().find(|notice| notice.error).expect("the failed asset is reported as an error notice"); @@ -889,6 +895,7 @@ mod tests { ); // A clean generation afterwards reports the success line with no error notice (#11079 control). app.ui.notices.clear(); + app.session.execute("file.scripts.scriptEventsManager", json!({"enabled": false})).unwrap(); std::fs::remove_file(assets.join("blocked")).unwrap(); let revision = app.session.active().unwrap().revision; app.saved(doc, revision, &path, &[], false); From be3f632402b139f8fdbf50738408f1eb5864142b Mon Sep 17 00:00:00 2001 From: FredApps Date: Wed, 4 Nov 2026 13:58:19 +0100 Subject: [PATCH 5/5] test: format save hook regression --- crates/ui-egui/src/app/files.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index 7fcc1c49a5..ae230542ce 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -872,7 +872,9 @@ mod tests { } app.session.prefs.edit(|p| p.plug_ins.generator_enabled = true); app.session.file_menu.image_assets.push(doc); - app.session.execute("file.scripts.scriptEventsManager", json!({"enabled": true, "add": {"event": "saveDocument", "steps": [["file.close", {"document": 0}]]}})).unwrap(); + app.session + .execute("file.scripts.scriptEventsManager", json!({"enabled": true, "add": {"event": "saveDocument", "steps": [["file.close", {"document": 0}]]}})) + .unwrap(); let revision = app.session.active().unwrap().revision; app.saved(doc, revision, &path, &[], false);