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

* wip: the diagnosis of #10181 (the bug reproduces on current main)

sketch.project has .enabled(in_sketch) (crates/engine/src/cmd/sketch_project.rs:24)
and in_sketch (crates/engine/src/cmd/mod.rs:285) answers 'no sketch is being edited'.
Pressing P outside a sketch goes keymap::press -> sketch_tool_for
(crates/ui-egui/src/keymap.rs:451-457) -> app.start("sketch.create") with
d.then_start = Some("sketch.project"): the sketch IS created, but the Project
dialog opens and the command is refused, so the dialog shows the red row and the
'Create Issue...' button, which opens the Report a bug form over the viewport.

The probe here reproduces the bug on the CURRENT main (two variants). It is a
diagnostic probe, not the regression test: it must be replaced before a PR.

* test: a context error offers no Create Issue button (#10181)

The Project panel showed the red row for a CONTEXT error ('sketch.project is not
available right now: no sketch is being edited') and offered the 'Create Issue...'
button, which opens the Report a bug form over the viewport. A context error is
not something to report, so the panel must not offer it.

RED: the test fails with the exact message of the issue.

* fix: a context error is not something to report (#10181)

The Project panel offered "Create Issue..." for the error the engine
raises when the command is not available in the current context
("`sketch.project` is not available right now: no sketch is being
edited (Create Sketch or Edit Sketch first)"). That refusal is guidance
about the context, not a failure of the design, so there is nothing to
report: ending the sketch under an open Project panel should not invite
the user to file a bug.

error_rows already spared the missing-pick errors ("select ...", "pick
...") the same way. It now spares the context refusals too, using the
engine's own kind rather than the message text: CommandSpec gains
disabled_refusal, which is the engine's own Disabled refusal for the
command in the current session, and the UI matches the dialog's error
against it. A real failure of the command (an invalid face, say) still
shows the red row with "Create Issue...".

* style: rustfmt the test of #10181

The formatter joins the two asserts of the test onto one line (the
repository sets max_width = 150 and use_small_heuristics = Max). The
tokens of the file are unchanged: the diff is the line breaks of the
asserts and nothing else.
This commit is contained in:
Homero Thompson
2026-11-02 00:09:40 +00:00
committed by GitHub
parent 5e7f3651fb
commit 6459c9fcf0
3 changed files with 50 additions and 0 deletions
+6
View File
@@ -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 {
+15
View File
@@ -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));
@@ -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();