diff --git a/src/lang/errors.ts b/src/lang/errors.ts index df6d6b371..d6085a303 100644 --- a/src/lang/errors.ts +++ b/src/lang/errors.ts @@ -159,7 +159,7 @@ export class KCLTypeError extends KCLError { } } -export class KCLUnimplementedError extends KCLError { +export class KCLIoError extends KCLError { constructor( msg: string, sourceRange: SourceRange, @@ -169,7 +169,7 @@ export class KCLUnimplementedError extends KCLError { filenames: { [x: number]: ModulePath | undefined } ) { super( - 'unimplemented', + 'io', msg, sourceRange, operations, @@ -177,7 +177,7 @@ export class KCLUnimplementedError extends KCLError { artifactGraph, filenames ) - Object.setPrototypeOf(this, KCLUnimplementedError.prototype) + Object.setPrototypeOf(this, KCLIoError.prototype) } } diff --git a/src/wasm-lib/kcl/src/errors.rs b/src/wasm-lib/kcl/src/errors.rs index 3168f75ff..226125a82 100644 --- a/src/wasm-lib/kcl/src/errors.rs +++ b/src/wasm-lib/kcl/src/errors.rs @@ -87,8 +87,8 @@ pub enum KclError { ImportCycle(KclErrorDetails), #[error("type: {0:?}")] Type(KclErrorDetails), - #[error("unimplemented: {0:?}")] - Unimplemented(KclErrorDetails), + #[error("i/o: {0:?}")] + Io(KclErrorDetails), #[error("unexpected: {0:?}")] Unexpected(KclErrorDetails), #[error("value already defined: {0:?}")] @@ -268,7 +268,7 @@ impl miette::Diagnostic for ReportWithOutputs { KclError::Semantic(_) => "Semantic", KclError::ImportCycle(_) => "ImportCycle", KclError::Type(_) => "Type", - KclError::Unimplemented(_) => "Unimplemented", + KclError::Io(_) => "I/O", KclError::Unexpected(_) => "Unexpected", KclError::ValueAlreadyDefined(_) => "ValueAlreadyDefined", KclError::UndefinedValue(_) => "UndefinedValue", @@ -318,7 +318,7 @@ impl miette::Diagnostic for Report { KclError::Semantic(_) => "Semantic", KclError::ImportCycle(_) => "ImportCycle", KclError::Type(_) => "Type", - KclError::Unimplemented(_) => "Unimplemented", + KclError::Io(_) => "I/O", KclError::Unexpected(_) => "Unexpected", KclError::ValueAlreadyDefined(_) => "ValueAlreadyDefined", KclError::UndefinedValue(_) => "UndefinedValue", @@ -377,7 +377,7 @@ impl KclError { KclError::Semantic(_) => "semantic", KclError::ImportCycle(_) => "import cycle", KclError::Type(_) => "type", - KclError::Unimplemented(_) => "unimplemented", + KclError::Io(_) => "i/o", KclError::Unexpected(_) => "unexpected", KclError::ValueAlreadyDefined(_) => "value already defined", KclError::UndefinedValue(_) => "undefined value", @@ -394,7 +394,7 @@ impl KclError { KclError::Semantic(e) => e.source_ranges.clone(), KclError::ImportCycle(e) => e.source_ranges.clone(), KclError::Type(e) => e.source_ranges.clone(), - KclError::Unimplemented(e) => e.source_ranges.clone(), + KclError::Io(e) => e.source_ranges.clone(), KclError::Unexpected(e) => e.source_ranges.clone(), KclError::ValueAlreadyDefined(e) => e.source_ranges.clone(), KclError::UndefinedValue(e) => e.source_ranges.clone(), @@ -412,7 +412,7 @@ impl KclError { KclError::Semantic(e) => &e.message, KclError::ImportCycle(e) => &e.message, KclError::Type(e) => &e.message, - KclError::Unimplemented(e) => &e.message, + KclError::Io(e) => &e.message, KclError::Unexpected(e) => &e.message, KclError::ValueAlreadyDefined(e) => &e.message, KclError::UndefinedValue(e) => &e.message, @@ -430,7 +430,7 @@ impl KclError { KclError::Semantic(e) => e.source_ranges = source_ranges, KclError::ImportCycle(e) => e.source_ranges = source_ranges, KclError::Type(e) => e.source_ranges = source_ranges, - KclError::Unimplemented(e) => e.source_ranges = source_ranges, + KclError::Io(e) => e.source_ranges = source_ranges, KclError::Unexpected(e) => e.source_ranges = source_ranges, KclError::ValueAlreadyDefined(e) => e.source_ranges = source_ranges, KclError::UndefinedValue(e) => e.source_ranges = source_ranges, @@ -450,7 +450,7 @@ impl KclError { KclError::Semantic(e) => e.source_ranges.extend(source_ranges), KclError::ImportCycle(e) => e.source_ranges.extend(source_ranges), KclError::Type(e) => e.source_ranges.extend(source_ranges), - KclError::Unimplemented(e) => e.source_ranges.extend(source_ranges), + KclError::Io(e) => e.source_ranges.extend(source_ranges), KclError::Unexpected(e) => e.source_ranges.extend(source_ranges), KclError::ValueAlreadyDefined(e) => e.source_ranges.extend(source_ranges), KclError::UndefinedValue(e) => e.source_ranges.extend(source_ranges), diff --git a/src/wasm-lib/kcl/src/fs/local.rs b/src/wasm-lib/kcl/src/fs/local.rs index 562cecac0..2d0f665fd 100644 --- a/src/wasm-lib/kcl/src/fs/local.rs +++ b/src/wasm-lib/kcl/src/fs/local.rs @@ -31,7 +31,7 @@ impl FileSystem for FileManager { source_range: SourceRange, ) -> Result, KclError> { tokio::fs::read(&path).await.map_err(|e| { - KclError::Engine(KclErrorDetails { + KclError::Io(KclErrorDetails { message: format!("Failed to read file `{}`: {}", path.as_ref().display(), e), source_ranges: vec![source_range], }) @@ -44,7 +44,7 @@ impl FileSystem for FileManager { source_range: SourceRange, ) -> Result { tokio::fs::read_to_string(&path).await.map_err(|e| { - KclError::Engine(KclErrorDetails { + KclError::Io(KclErrorDetails { message: format!("Failed to read file `{}`: {}", path.as_ref().display(), e), source_ranges: vec![source_range], }) @@ -60,7 +60,7 @@ impl FileSystem for FileManager { if e.kind() == std::io::ErrorKind::NotFound { Ok(false) } else { - Err(KclError::Engine(KclErrorDetails { + Err(KclError::Io(KclErrorDetails { message: format!("Failed to check if file `{}` exists: {}", path.as_ref().display(), e), source_ranges: vec![source_range], })) @@ -82,7 +82,7 @@ impl FileSystem for FileManager { } let mut read_dir = tokio::fs::read_dir(&path).await.map_err(|e| { - KclError::Engine(KclErrorDetails { + KclError::Io(KclErrorDetails { message: format!("Failed to read directory `{}`: {}", path.display(), e), source_ranges: vec![source_range], }) diff --git a/src/wasm-lib/kcl/tests/import_file_not_exist_error/execution_error.snap b/src/wasm-lib/kcl/tests/import_file_not_exist_error/execution_error.snap index 5af471db6..44ffd0933 100644 --- a/src/wasm-lib/kcl/tests/import_file_not_exist_error/execution_error.snap +++ b/src/wasm-lib/kcl/tests/import_file_not_exist_error/execution_error.snap @@ -2,9 +2,9 @@ source: kcl/src/simulation_tests.rs description: Error from executing import_file_not_exist_error.kcl --- -KCL Engine error +KCL I/O error - × engine: Failed to read file `tests/import_file_not_exist_error/not- + × i/o: Failed to read file `tests/import_file_not_exist_error/not- │ exist.kcl`: No such file or directory (os error 2) ╭──── 1 │ import hotdog from "not-exist.kcl"