Show KCL backtraces (#7033)
* Add backtrace to errors * Add display of backtraces with hints * Change pane badge to only show count of errors * Fix property name to not collide with Error superclass * Increase min stack again * Add e2e test that checks that the diagnostics are created in CodeMirror * Remove unneeded code * Change to the new hotness
This commit is contained in:
@ -64,16 +64,16 @@ impl FaceTag {
|
||||
match self {
|
||||
FaceTag::Tag(ref t) => args.get_adjacent_face_to_tag(exec_state, t, must_be_planar).await,
|
||||
FaceTag::StartOrEnd(StartOrEnd::Start) => solid.start_cap_id.ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
message: "Expected a start face".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
})
|
||||
KclError::Type(KclErrorDetails::new(
|
||||
"Expected a start face".to_string(),
|
||||
vec![args.source_range],
|
||||
))
|
||||
}),
|
||||
FaceTag::StartOrEnd(StartOrEnd::End) => solid.end_cap_id.ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
message: "Expected an end face".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
})
|
||||
KclError::Type(KclErrorDetails::new(
|
||||
"Expected an end face".to_string(),
|
||||
vec![args.source_range],
|
||||
))
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -329,19 +329,18 @@ async fn straight_line(
|
||||
let from = sketch.current_pen_position()?;
|
||||
let (point, is_absolute) = match (end_absolute, end) {
|
||||
(Some(_), Some(_)) => {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message: "You cannot give both `end` and `endAbsolute` params, you have to choose one or the other"
|
||||
.to_owned(),
|
||||
}));
|
||||
return Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"You cannot give both `end` and `endAbsolute` params, you have to choose one or the other".to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
(Some(end_absolute), None) => (end_absolute, true),
|
||||
(None, Some(end)) => (end, false),
|
||||
(None, None) => {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message: format!("You must supply either `{relative_name}` or `endAbsolute` arguments"),
|
||||
}));
|
||||
return Err(KclError::Semantic(KclErrorDetails::new(
|
||||
format!("You must supply either `{relative_name}` or `endAbsolute` arguments"),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
@ -608,10 +607,10 @@ async fn inner_angled_line(
|
||||
.filter(|x| x.is_some())
|
||||
.count();
|
||||
if options_given > 1 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: " one of `length`, `lengthX`, `lengthY`, `endAbsoluteX`, `endAbsoluteY` can be given".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
" one of `length`, `lengthX`, `lengthY`, `endAbsoluteX`, `endAbsoluteY` can be given".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
if let Some(length_x) = length_x {
|
||||
return inner_angled_line_of_x_length(angle, length_x, sketch, tag, exec_state, args).await;
|
||||
@ -636,15 +635,14 @@ async fn inner_angled_line(
|
||||
(None, None, None, None, Some(end_absolute_y)) => {
|
||||
inner_angled_line_to_y(angle_degrees, end_absolute_y, sketch, tag, exec_state, args).await
|
||||
}
|
||||
(None, None, None, None, None) => Err(KclError::Type(KclErrorDetails {
|
||||
message: "One of `length`, `lengthX`, `lengthY`, `endAbsoluteX`, `endAbsoluteY` must be given".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
})),
|
||||
_ => Err(KclError::Type(KclErrorDetails {
|
||||
message: "Only One of `length`, `lengthX`, `lengthY`, `endAbsoluteX`, `endAbsoluteY` can be given"
|
||||
.to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
})),
|
||||
(None, None, None, None, None) => Err(KclError::Type(KclErrorDetails::new(
|
||||
"One of `length`, `lengthX`, `lengthY`, `endAbsoluteX`, `endAbsoluteY` must be given".to_string(),
|
||||
vec![args.source_range],
|
||||
))),
|
||||
_ => Err(KclError::Type(KclErrorDetails::new(
|
||||
"Only One of `length`, `lengthX`, `lengthY`, `endAbsoluteX`, `endAbsoluteY` can be given".to_owned(),
|
||||
vec![args.source_range],
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -715,17 +713,17 @@ async fn inner_angled_line_of_x_length(
|
||||
args: Args,
|
||||
) -> Result<Sketch, KclError> {
|
||||
if angle_degrees.abs() == 270.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have an x constrained angle of 270 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have an x constrained angle of 270 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
if angle_degrees.abs() == 90.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have an x constrained angle of 90 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have an x constrained angle of 90 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
let to = get_y_component(Angle::from_degrees(angle_degrees), length.n);
|
||||
@ -747,17 +745,17 @@ async fn inner_angled_line_to_x(
|
||||
let from = sketch.current_pen_position()?;
|
||||
|
||||
if angle_degrees.abs() == 270.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have an x constrained angle of 270 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have an x constrained angle of 270 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
if angle_degrees.abs() == 90.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have an x constrained angle of 90 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have an x constrained angle of 90 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
let x_component = x_to.to_length_units(from.units) - from.x;
|
||||
@ -782,17 +780,17 @@ async fn inner_angled_line_of_y_length(
|
||||
args: Args,
|
||||
) -> Result<Sketch, KclError> {
|
||||
if angle_degrees.abs() == 0.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have a y constrained angle of 0 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have a y constrained angle of 0 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
if angle_degrees.abs() == 180.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have a y constrained angle of 180 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have a y constrained angle of 180 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
let to = get_x_component(Angle::from_degrees(angle_degrees), length.n);
|
||||
@ -814,17 +812,17 @@ async fn inner_angled_line_to_y(
|
||||
let from = sketch.current_pen_position()?;
|
||||
|
||||
if angle_degrees.abs() == 0.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have a y constrained angle of 0 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have a y constrained angle of 0 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
if angle_degrees.abs() == 180.0 {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Cannot have a y constrained angle of 180 degrees".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Cannot have a y constrained angle of 180 degrees".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
let y_component = y_to.to_length_units(from.units) - from.y;
|
||||
@ -898,10 +896,10 @@ pub async fn inner_angled_line_that_intersects(
|
||||
) -> Result<Sketch, KclError> {
|
||||
let intersect_path = args.get_tag_engine_info(exec_state, &intersect_tag)?;
|
||||
let path = intersect_path.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
message: format!("Expected an intersect path with a path, found `{:?}`", intersect_path),
|
||||
source_ranges: vec![args.source_range],
|
||||
})
|
||||
KclError::Type(KclErrorDetails::new(
|
||||
format!("Expected an intersect path with a path, found `{:?}`", intersect_path),
|
||||
vec![args.source_range],
|
||||
))
|
||||
})?;
|
||||
|
||||
let from = sketch.current_pen_position()?;
|
||||
@ -1176,10 +1174,10 @@ async fn inner_start_sketch_on(
|
||||
SketchData::Plane(plane) => {
|
||||
if plane.value == crate::exec::PlaneType::Uninit {
|
||||
if plane.info.origin.units == UnitLen::Unknown {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
message: "Origin of plane has unknown units".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"Origin of plane has unknown units".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
let plane = make_sketch_plane_from_orientation(plane.info.into_plane_data(), exec_state, args).await?;
|
||||
Ok(SketchSurface::Plane(plane))
|
||||
@ -1200,10 +1198,10 @@ async fn inner_start_sketch_on(
|
||||
}
|
||||
SketchData::Solid(solid) => {
|
||||
let Some(tag) = face else {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Expected a tag for the face to sketch on".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Expected a tag for the face to sketch on".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
};
|
||||
let face = start_sketch_on_face(solid, tag, exec_state, args).await?;
|
||||
|
||||
@ -1715,12 +1713,10 @@ pub(crate) async fn inner_arc(
|
||||
absolute_arc(&args, id, exec_state, sketch, from, interior_absolute, end_absolute, tag).await
|
||||
}
|
||||
_ => {
|
||||
Err(KclError::Type(KclErrorDetails {
|
||||
message:
|
||||
"Invalid combination of arguments. Either provide (angleStart, angleEnd, radius) or (endAbsolute, interiorAbsolute)"
|
||||
.to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}))
|
||||
Err(KclError::Type(KclErrorDetails::new(
|
||||
"Invalid combination of arguments. Either provide (angleStart, angleEnd, radius) or (endAbsolute, interiorAbsolute)".to_owned(),
|
||||
vec![args.source_range],
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1804,10 +1800,10 @@ pub async fn relative_arc(
|
||||
let radius = radius.to_length_units(from.units);
|
||||
let (center, end) = arc_center_and_end(from.ignore_units(), a_start, a_end, radius);
|
||||
if a_start == a_end {
|
||||
return Err(KclError::Type(KclErrorDetails {
|
||||
message: "Arc start and end angles must be different".to_string(),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
return Err(KclError::Type(KclErrorDetails::new(
|
||||
"Arc start and end angles must be different".to_string(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
let ccw = a_start < a_end;
|
||||
|
||||
@ -1958,19 +1954,18 @@ async fn inner_tangential_arc(
|
||||
let data = TangentialArcData::RadiusAndOffset { radius, offset: angle };
|
||||
inner_tangential_arc_radius_angle(data, sketch, tag, exec_state, args).await
|
||||
}
|
||||
(Some(_), Some(_), None, None) => Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message: "You cannot give both `end` and `endAbsolute` params, you have to choose one or the other"
|
||||
.to_owned(),
|
||||
})),
|
||||
(None, None, Some(_), None) | (None, None, None, Some(_)) => Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message: "You must supply both `radius` and `angle` arguments".to_owned(),
|
||||
})),
|
||||
(_, _, _, _) => Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message: "You must supply `end`, `endAbsolute`, or both `radius` and `angle` arguments".to_owned(),
|
||||
})),
|
||||
(Some(_), Some(_), None, None) => Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"You cannot give both `end` and `endAbsolute` params, you have to choose one or the other".to_owned(),
|
||||
vec![args.source_range],
|
||||
))),
|
||||
(None, None, Some(_), None) | (None, None, None, Some(_)) => Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"You must supply both `radius` and `angle` arguments".to_owned(),
|
||||
vec![args.source_range],
|
||||
))),
|
||||
(_, _, _, _) => Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"You must supply `end`, `endAbsolute`, or both `radius` and `angle` arguments".to_owned(),
|
||||
vec![args.source_range],
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2121,19 +2116,17 @@ async fn inner_tangential_arc_to_point(
|
||||
});
|
||||
|
||||
if result.center[0].is_infinite() {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message:
|
||||
"could not sketch tangential arc, because its center would be infinitely far away in the X direction"
|
||||
.to_owned(),
|
||||
}));
|
||||
return Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"could not sketch tangential arc, because its center would be infinitely far away in the X direction"
|
||||
.to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
} else if result.center[1].is_infinite() {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
source_ranges: vec![args.source_range],
|
||||
message:
|
||||
"could not sketch tangential arc, because its center would be infinitely far away in the Y direction"
|
||||
.to_owned(),
|
||||
}));
|
||||
return Err(KclError::Semantic(KclErrorDetails::new(
|
||||
"could not sketch tangential arc, because its center would be infinitely far away in the Y direction"
|
||||
.to_owned(),
|
||||
vec![args.source_range],
|
||||
)));
|
||||
}
|
||||
|
||||
let delta = if is_absolute {
|
||||
|
Reference in New Issue
Block a user