Change artifact panics to runtime errors (#7177)
* Change artifact panics to runtime errors * Condense format!() * Remove unwrap
This commit is contained in:
@ -20,6 +20,14 @@ use crate::{
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mermaid_tests;
|
mod mermaid_tests;
|
||||||
|
|
||||||
|
macro_rules! internal_error {
|
||||||
|
($range:expr, $($rest:tt)*) => {{
|
||||||
|
let message = format!($($rest)*);
|
||||||
|
debug_assert!(false, "{}", &message);
|
||||||
|
return Err(KclError::Internal(KclErrorDetails::new(message, vec![$range])));
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
/// A command that may create or update artifacts on the TS side. Because
|
/// A command that may create or update artifacts on the TS side. Because
|
||||||
/// engine commands are batched, we don't have the response yet when these are
|
/// engine commands are batched, we don't have the response yet when these are
|
||||||
/// created.
|
/// created.
|
||||||
@ -992,7 +1000,10 @@ fn artifacts_to_update(
|
|||||||
let path_id = ArtifactId::new(match cmd {
|
let path_id = ArtifactId::new(match cmd {
|
||||||
ModelingCmd::ClosePath(c) => c.path_id,
|
ModelingCmd::ClosePath(c) => c.path_id,
|
||||||
ModelingCmd::ExtendPath(e) => e.path.into(),
|
ModelingCmd::ExtendPath(e) => e.path.into(),
|
||||||
_ => unreachable!(),
|
_ => internal_error!(
|
||||||
|
range,
|
||||||
|
"Close or extend path command variant not handled: id={id:?}, cmd={cmd:?}"
|
||||||
|
),
|
||||||
});
|
});
|
||||||
let mut return_arr = Vec::new();
|
let mut return_arr = Vec::new();
|
||||||
return_arr.push(Artifact::Segment(Segment {
|
return_arr.push(Artifact::Segment(Segment {
|
||||||
@ -1032,7 +1043,7 @@ fn artifacts_to_update(
|
|||||||
ModelingCmd::Revolve(_) => SweepSubType::Revolve,
|
ModelingCmd::Revolve(_) => SweepSubType::Revolve,
|
||||||
ModelingCmd::RevolveAboutEdge(_) => SweepSubType::RevolveAboutEdge,
|
ModelingCmd::RevolveAboutEdge(_) => SweepSubType::RevolveAboutEdge,
|
||||||
ModelingCmd::Sweep(_) => SweepSubType::Sweep,
|
ModelingCmd::Sweep(_) => SweepSubType::Sweep,
|
||||||
_ => unreachable!(),
|
_ => internal_error!(range, "Sweep-like command variant not handled: id={id:?}, cmd={cmd:?}",),
|
||||||
};
|
};
|
||||||
let mut return_arr = Vec::new();
|
let mut return_arr = Vec::new();
|
||||||
let target = ArtifactId::from(target);
|
let target = ArtifactId::from(target);
|
||||||
@ -1297,7 +1308,13 @@ fn artifacts_to_update(
|
|||||||
let edge_id = if let Some(edge_id) = cmd.edge_id {
|
let edge_id = if let Some(edge_id) = cmd.edge_id {
|
||||||
ArtifactId::new(edge_id)
|
ArtifactId::new(edge_id)
|
||||||
} else {
|
} else {
|
||||||
cmd.edge_ids.first().unwrap().into()
|
let Some(edge_id) = cmd.edge_ids.first() else {
|
||||||
|
internal_error!(
|
||||||
|
range,
|
||||||
|
"Solid3dFilletEdge command has no edge ID: id={id:?}, cmd={cmd:?}"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
edge_id.into()
|
||||||
};
|
};
|
||||||
return_arr.push(Artifact::EdgeCut(EdgeCut {
|
return_arr.push(Artifact::EdgeCut(EdgeCut {
|
||||||
id,
|
id,
|
||||||
@ -1366,7 +1383,10 @@ fn artifacts_to_update(
|
|||||||
let solid_ids = union.solid_ids.iter().copied().map(ArtifactId::new).collect::<Vec<_>>();
|
let solid_ids = union.solid_ids.iter().copied().map(ArtifactId::new).collect::<Vec<_>>();
|
||||||
(CompositeSolidSubType::Union, solid_ids, Vec::new())
|
(CompositeSolidSubType::Union, solid_ids, Vec::new())
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => internal_error!(
|
||||||
|
range,
|
||||||
|
"Boolean or composite command variant not handled: id={id:?}, cmd={cmd:?}"
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut new_solid_ids = vec![id];
|
let mut new_solid_ids = vec![id];
|
||||||
|
Reference in New Issue
Block a user