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:
Jonathan Tran
2025-05-19 14:13:10 -04:00
committed by GitHub
parent bfa2f67393
commit ddb034b14d
53 changed files with 1543 additions and 1322 deletions

View File

@ -858,10 +858,9 @@ impl ExecutorContext {
for module in modules {
let Some((import_stmt, module_id, module_path, repr)) = universe.get(&module) else {
return Err(KclErrorWithOutputs::no_outputs(KclError::Internal(KclErrorDetails {
message: format!("Module {module} not found in universe"),
source_ranges: Default::default(),
})));
return Err(KclErrorWithOutputs::no_outputs(KclError::Internal(
KclErrorDetails::new(format!("Module {module} not found in universe"), Default::default()),
)));
};
let module_id = *module_id;
let module_path = module_path.clone();
@ -921,10 +920,10 @@ impl ExecutorContext {
result.map(|val| ModuleRepr::Foreign(geom.clone(), val))
}
ModuleRepr::Dummy | ModuleRepr::Root => Err(KclError::Internal(KclErrorDetails {
message: format!("Module {module_path} not found in universe"),
source_ranges: vec![source_range],
})),
ModuleRepr::Dummy | ModuleRepr::Root => Err(KclError::Internal(KclErrorDetails::new(
format!("Module {module_path} not found in universe"),
vec![source_range],
))),
}
};
@ -1288,10 +1287,10 @@ impl ExecutorContext {
.await?;
let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Export { files } = resp else {
return Err(KclError::Internal(crate::errors::KclErrorDetails {
message: format!("Expected Export response, got {resp:?}",),
source_ranges: vec![SourceRange::default()],
}));
return Err(KclError::Internal(crate::errors::KclErrorDetails::new(
format!("Expected Export response, got {resp:?}",),
vec![SourceRange::default()],
)));
};
Ok(files)
@ -1308,10 +1307,10 @@ impl ExecutorContext {
coords: *kittycad_modeling_cmds::coord::KITTYCAD,
created: if deterministic_time {
Some("2021-01-01T00:00:00Z".parse().map_err(|e| {
KclError::Internal(crate::errors::KclErrorDetails {
message: format!("Failed to parse date: {}", e),
source_ranges: vec![SourceRange::default()],
})
KclError::Internal(crate::errors::KclErrorDetails::new(
format!("Failed to parse date: {}", e),
vec![SourceRange::default()],
))
})?)
} else {
None
@ -1388,10 +1387,10 @@ pub(crate) async fn parse_execute_with_project_dir(
let exec_ctxt = ExecutorContext {
engine: Arc::new(Box::new(
crate::engine::conn_mock::EngineConnection::new().await.map_err(|err| {
KclError::Internal(crate::errors::KclErrorDetails {
message: format!("Failed to create mock engine connection: {}", err),
source_ranges: vec![SourceRange::default()],
})
KclError::Internal(crate::errors::KclErrorDetails::new(
format!("Failed to create mock engine connection: {}", err),
vec![SourceRange::default()],
))
})?,
)),
fs: Arc::new(crate::fs::FileManager::new()),
@ -1804,10 +1803,10 @@ foo
let err = result.unwrap_err();
assert_eq!(
err,
KclError::Syntax(KclErrorDetails {
message: "Unexpected token: #".to_owned(),
source_ranges: vec![SourceRange::new(14, 15, ModuleId::default())],
}),
KclError::Syntax(KclErrorDetails::new(
"Unexpected token: #".to_owned(),
vec![SourceRange::new(14, 15, ModuleId::default())],
)),
);
}
@ -2063,10 +2062,10 @@ notTagIdentifier = !myTag";
// TODO: We don't currently parse this, but we should. It should be
// a runtime error instead.
parse_execute(code10).await.unwrap_err(),
KclError::Syntax(KclErrorDetails {
message: "Unexpected token: !".to_owned(),
source_ranges: vec![SourceRange::new(10, 11, ModuleId::default())],
})
KclError::Syntax(KclErrorDetails::new(
"Unexpected token: !".to_owned(),
vec![SourceRange::new(10, 11, ModuleId::default())],
))
);
let code11 = "
@ -2076,10 +2075,10 @@ notPipeSub = 1 |> identity(!%))";
// TODO: We don't currently parse this, but we should. It should be
// a runtime error instead.
parse_execute(code11).await.unwrap_err(),
KclError::Syntax(KclErrorDetails {
message: "Unexpected token: |>".to_owned(),
source_ranges: vec![SourceRange::new(44, 46, ModuleId::default())],
})
KclError::Syntax(KclErrorDetails::new(
"Unexpected token: |>".to_owned(),
vec![SourceRange::new(44, 46, ModuleId::default())],
))
);
// TODO: Add these tests when we support these types.