KCL: Use named fields for KclError (#7321)
We've changed the unnamed field of `KclError` variants to a named called `details`. To clarify: previously KCL errors looked like this: ```rust pub enum KclError { Lexical(KclErrorDetails), Syntax(KclErrorDetails), ``` Now they look like this: ```rust pub enum KclError { Lexical { details: KclErrorDetails }, Syntax { details: KclErrorDetails }, } ``` This lets us more easily add fields to the errors. For example, in the UndefinedValue case, adding a field for what the undefined name was. This PR refactors the code to make my PR in https://github.com/KittyCAD/modeling-app/pull/7309 much easier. Pure refactor, should not change any behaviour.
This commit is contained in:
@ -66,7 +66,7 @@ async fn inner_extrude(
|
||||
let mut solids = Vec::new();
|
||||
|
||||
if symmetric.unwrap_or(false) && bidirectional_length.is_some() {
|
||||
return Err(KclError::Semantic(KclErrorDetails::new(
|
||||
return Err(KclError::new_semantic(KclErrorDetails::new(
|
||||
"You cannot give both `symmetric` and `bidirectional` params, you have to choose one or the other"
|
||||
.to_owned(),
|
||||
vec![args.source_range],
|
||||
@ -153,7 +153,7 @@ pub(crate) async fn do_post_extrude<'a>(
|
||||
// The "get extrusion face info" API call requires *any* edge on the sketch being extruded.
|
||||
// So, let's just use the first one.
|
||||
let Some(any_edge_id) = sketch.paths.first().map(|edge| edge.get_base().geo_meta.id) else {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
"Expected a non-empty sketch".to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
@ -278,7 +278,7 @@ pub(crate) async fn do_post_extrude<'a>(
|
||||
// Add the tags for the start or end caps.
|
||||
if let Some(tag_start) = named_cap_tags.start {
|
||||
let Some(start_cap_id) = start_cap_id else {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
format!(
|
||||
"Expected a start cap ID for tag `{}` for extrusion of sketch {:?}",
|
||||
tag_start.name, sketch.id
|
||||
@ -298,7 +298,7 @@ pub(crate) async fn do_post_extrude<'a>(
|
||||
}
|
||||
if let Some(tag_end) = named_cap_tags.end {
|
||||
let Some(end_cap_id) = end_cap_id else {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
format!(
|
||||
"Expected an end cap ID for tag `{}` for extrusion of sketch {:?}",
|
||||
tag_end.name, sketch.id
|
||||
|
Reference in New Issue
Block a user