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:
@ -36,14 +36,14 @@ async fn inner_shell(
|
||||
args: Args,
|
||||
) -> Result<Vec<Solid>, KclError> {
|
||||
if faces.is_empty() {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
"You must shell at least one face".to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
if solids.is_empty() {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
"You must shell at least one solid".to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
@ -63,7 +63,7 @@ async fn inner_shell(
|
||||
}
|
||||
|
||||
if face_ids.is_empty() {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
"Expected at least one valid face".to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
@ -72,7 +72,7 @@ async fn inner_shell(
|
||||
// Make sure all the solids have the same id, as we are going to shell them all at
|
||||
// once.
|
||||
if !solids.iter().all(|eg| eg.id == solids[0].id) {
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
return Err(KclError::new_type(KclErrorDetails::new(
|
||||
"All solids stem from the same root object, like multiple sketch on face extrusions, etc.".to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
|
Reference in New Issue
Block a user