From 46552bdc3ab82dd8390871480e26df3262f9c798 Mon Sep 17 00:00:00 2001 From: Victor Santos Oliveira <56417388+Vittuu@users.noreply.github.com> Date: Tue, 27 Oct 2026 12:39:31 +0000 Subject: [PATCH] Profiles: explain public selection forms in parameter errors (#7180) (#7491) * claim: #7180 public profile selection diagnostics * fix(engine): explain public profile selection forms --- crates/engine/src/cmd/features.rs | 6 ++++ crates/engine/src/schema/tests.rs | 57 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs index 89140d982..58668a8a3 100644 --- a/crates/engine/src/cmd/features.rs +++ b/crates/engine/src/cmd/features.rs @@ -517,6 +517,12 @@ pub(crate) fn profiles(p: &Value, cmd: &str) -> Result { if fields.get("type").and_then(Value::as_str) == Some("whole_boundaries") { return solidcraft_doc::whole_profile_selection_from_value(v).map_err(|error| bad(cmd, error.to_string())); } + if !fields.contains_key("offset_boundaries") && fields.get("type").and_then(Value::as_str) != Some("offset_boundaries") { + return Err(bad( + cmd, + r#"`profiles` must be `"all"`, an index such as `0`, indices such as `[0]`, point picks such as `[{"point": [0, 0]}]` or curve-id picks such as `[{"curves": ["c1"]}]`"#, + )); + } let associations = fields .get("offset_boundaries") .or_else(|| (fields.get("type").and_then(Value::as_str) == Some("offset_boundaries")).then(|| fields.get("associations")).flatten()) diff --git a/crates/engine/src/schema/tests.rs b/crates/engine/src/schema/tests.rs index 8f193b312..66bfd7ff0 100644 --- a/crates/engine/src/schema/tests.rs +++ b/crates/engine/src/schema/tests.rs @@ -128,6 +128,63 @@ fn profiles_match_features_profiles() { assert_eq!(issue(json!(vec![0; 10_001])), vec!["`profiles` must have at most 10000 items"]); } +#[test] +fn unsupported_profile_objects_offer_valid_public_examples() { + let contract = TypedContract::::new(); + for profiles in [ + json!({"type": "curves", "loops": [["c1"], ["c2"]]}), + json!({"type": "curves", "loops": [["c1"]]}), + json!({"type": "index", "index": 0}), + json!({"type": "indices", "indices": [0]}), + json!({"curves": ["c1"]}), + json!({}), + ] { + let issues = contract.check(&json!({"distance": 5, "profiles": profiles})); + assert_eq!(issues.len(), 1, "{profiles}: {issues:?}"); + let issue = issues.first().unwrap(); + assert_eq!(issue.path, "profiles"); + assert!(!issue.message.contains("offset_boundaries"), "{profiles}: {}", issue.message); + // The diagnostic is useful to scripts only if its public examples actually parse. + let examples: Vec = issue.message.split('`').skip(1).step_by(2).filter_map(|text| serde_json::from_str(text).ok()).collect(); + assert_eq!(examples.len(), 5, "{}", issue.message); + for example in examples { + let issues = contract.check(&json!({"distance": 5, "profiles": example})); + assert!(issues.is_empty(), "example {example}: {issues:?}"); + } + } + for profiles in [ + json!({"offset_boundaries": ["a"]}), + json!({"type": "offset_boundaries", "associations": ["a"]}), + json!({"type": "curves", "offset_boundaries": ["a"]}), + ] { + assert!(contract.check(&json!({"distance": 5, "profiles": profiles})).is_empty()); + } +} + +#[test] +fn unsupported_profile_objects_keep_the_design_in_every_check_mode() { + let mut session = Session::default(); + session.execute("sketch.create", &json!({"plane": "xy", "name": "Ring"})).unwrap(); + session.execute("sketch.circle.center", &json!({"center": [0, 0], "radius": 10})).unwrap(); + session.execute("sketch.circle.center", &json!({"center": [0, 0], "radius": 6})).unwrap(); + session.execute("sketch.finish", &json!({})).unwrap(); + let design = session.doc.to_json(); + let undo = session.undo.len(); + for mode in [ParamCheck::Off, ParamCheck::Warn, ParamCheck::Strict] { + session.param_check = mode; + for profiles in [json!({"type": "curves", "loops": [["c1"], ["c2"]]}), json!({"type": "index", "index": 0})] { + let error = session + .execute("solid.extrude", &json!({"sketch": "Ring", "distance": 3, "operation": "new", "profiles": profiles})) + .unwrap_err() + .to_string(); + assert!(error.contains("\"all\"") && error.contains("curves"), "{mode:?}: {error}"); + assert!(!error.contains("offset_boundaries"), "{mode:?}: {error}"); + assert_eq!(session.doc.to_json(), design); + assert_eq!(session.undo.len(), undo); + } + } +} + #[test] fn unknown_keys_get_suggestions() { let c = box_contract();