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:
@ -883,7 +883,7 @@ pub async fn walk_dir(dir: &std::path::PathBuf) -> Result<Vec<std::path::PathBuf
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn recast_dir(dir: &std::path::Path, options: &crate::FormatOptions) -> Result<(), anyhow::Error> {
|
||||
let files = walk_dir(&dir.to_path_buf()).await.map_err(|err| {
|
||||
crate::KclError::Internal(crate::errors::KclErrorDetails::new(
|
||||
crate::KclError::new_internal(crate::errors::KclErrorDetails::new(
|
||||
format!("Failed to walk directory `{}`: {:?}", dir.display(), err),
|
||||
vec![crate::SourceRange::default()],
|
||||
))
|
||||
@ -912,7 +912,7 @@ pub async fn recast_dir(dir: &std::path::Path, options: &crate::FormatOptions) -
|
||||
if ce.severity != crate::errors::Severity::Warning {
|
||||
let report = crate::Report {
|
||||
kcl_source: contents.to_string(),
|
||||
error: crate::KclError::Semantic(ce.clone().into()),
|
||||
error: crate::KclError::new_semantic(ce.clone().into()),
|
||||
filename: file.to_string_lossy().to_string(),
|
||||
};
|
||||
let report = miette::Report::new(report);
|
||||
|
Reference in New Issue
Block a user