Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

A context error is not something to report (#10181) (#10594)

Homero Thompson6459c9fcf00f
diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs
index 6ea963eda4..3880743956 100644
--- a/crates/engine/src/cmd/mod.rs
+++ b/crates/engine/src/cmd/mod.rs
@@ -249,6 +249,12 @@ impl CommandSpec {
other => other,
}
}
+ /// The refusal this command gives when it is not available in this session: none when it
+ /// is. It is the engine's own wording (`EngineError::Disabled`), so a caller that only has
+ /// the message can tell it from a failure of the command itself.
+ pub fn disabled_refusal(&self, s: &Session) -> Option<String> {
+ (self.enabled)(s).err().map(|why| crate::EngineError::Disabled(self.id.to_string(), why).to_string())
+ }
pub fn info(&self, s: &Session) -> CommandInfo {
let e = (self.enabled)(s);
let (label, icon) = match self.id {
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 39bc40ba0e..a69fde8ada 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -2865,6 +2865,16 @@ fn missing_pick(error: &str) -> bool {
awaiting_selection(error) || error.get(..5).is_some_and(|start| start.eq_ignore_ascii_case("pick "))
}
+/// A refusal that says the command is not available in this context ("`sketch.project` is not
+/// available right now: no sketch is being edited"): the engine's own `Disabled` refusal for the
+/// command this dialog runs, so the sketch ended or the mode changed under it. Guidance, not a
+/// failure of the design: there is nothing to report (#10181).
+fn context_refusal(app: &SolveApp, d: &Dialog, error: &str) -> bool {
+ let Some(id) = d.command() else { return false };
+ let Some(spec) = solidcraft_engine::find_command(id) else { return false };
+ spec.disabled_refusal(&app.session).is_some_and(|refusal| refusal == error)
+}
+
fn error_rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: &mut egui::Ui) {
if matches!(d.kind, Kind::SketchModify(_))
&& d.previews()
@@ -2884,8 +2894,13 @@ fn error_rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: &mut
}
// Other dialogs say so on OK ("select a plane first", "pick an axis"): that is what is
// left to pick, not a failure, so it is shown plainly, with no Create Issue (#3292, #3773).
+ // A command that is not available in this context ("`sketch.project` is not available
+ // right now: no sketch is being edited") is guidance too: the context went away, not the
+ // design, so there is nothing to report (#10181).
let rect = if missing_pick(&error) {
crate::ui_kit::text(ui, &shown_error(&error), crate::ui_kit::Text::Hint("missing_pick")).rect
+ } else if context_refusal(app, d, &error) {
+ crate::ui_kit::text(ui, &shown_error(&error), crate::ui_kit::Text::Hint("context")).rect
} else {
ui.vertical(|ui| {
crate::ui_kit::text(ui, &shown_error(&error), crate::ui_kit::Text::Report("error", true));
diff --git a/crates/ui-egui/src/dialogs_sketch_tests.rs b/crates/ui-egui/src/dialogs_sketch_tests.rs
index 58c5847560..b1569acce3 100644
--- a/crates/ui-egui/src/dialogs_sketch_tests.rs
+++ b/crates/ui-egui/src/dialogs_sketch_tests.rs
@@ -11,6 +11,35 @@ fn fixture() -> Harness {
h
}
+// ---------------------------------------------------------------------------
+// #10181
+// ---------------------------------------------------------------------------
+
+/// #10181: the Project panel left open by a sketch that ends offers its context error
+/// ("`sketch.project` is not available right now: no sketch is being edited") as something to
+/// report: the dialog draws a "Create Issue…" button for a refusal that only says the sketch
+/// is gone, which is guidance, not a failure.
+#[test]
+fn a_context_error_offers_no_create_issue_button_10181() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":40,"width":30,"height":20,"body_name":"Body1"})).unwrap();
+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
+ h.settle();
+ h.app.session.selection = vec![Sel::Face { body: "Body1".into(), index: 5, point: solidcraft_engine::geom::Vec3::new(20.0, 15.0, 20.0) }];
+ h.app.start("sketch.project");
+ h.frames(4);
+ assert!(h.app.dialog.as_ref().is_some_and(|d| matches!(d.kind, Kind::SketchProject { .. })), "the Project panel opens for the live sketch");
+ // The sketch ends while the Project panel is still open.
+ h.app.finish_sketch();
+ h.frames(4);
+ if h.app.dialog.is_some() {
+ h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap();
+ h.settle();
+ }
+ let error = h.app.dialog.as_ref().and_then(|d| d.error.clone());
+ assert!(scenario::handle_at("dialog:create_issue").is_none(), "the Project panel offers its context error as something to report: {error:?}");
+}
+
fn picked(h: &Harness, command: &str) -> Dialog {
let mut d = Dialog::for_command(&h.app, command).unwrap();
let sk = h.app.session.doc.sketch(h.app.session.active_sketch.unwrap()).unwrap();