diff --git a/rust/kcl-lib/src/errors.rs b/rust/kcl-lib/src/errors.rs index 6ab2dc277..e6fa260ff 100644 --- a/rust/kcl-lib/src/errors.rs +++ b/rust/kcl-lib/src/errors.rs @@ -129,6 +129,7 @@ impl From for KclError { #[serde(rename_all = "camelCase")] pub struct KclErrorWithOutputs { pub error: KclError, + pub non_fatal: Vec, #[cfg(feature = "artifact-graph")] pub operations: Vec, #[cfg(feature = "artifact-graph")] @@ -141,8 +142,10 @@ pub struct KclErrorWithOutputs { } impl KclErrorWithOutputs { + #[allow(clippy::too_many_arguments)] pub fn new( error: KclError, + non_fatal: Vec, #[cfg(feature = "artifact-graph")] operations: Vec, #[cfg(feature = "artifact-graph")] artifact_commands: Vec, #[cfg(feature = "artifact-graph")] artifact_graph: ArtifactGraph, @@ -152,6 +155,7 @@ impl KclErrorWithOutputs { ) -> Self { Self { error, + non_fatal, #[cfg(feature = "artifact-graph")] operations, #[cfg(feature = "artifact-graph")] @@ -166,6 +170,7 @@ impl KclErrorWithOutputs { pub fn no_outputs(error: KclError) -> Self { Self { error, + non_fatal: Default::default(), #[cfg(feature = "artifact-graph")] operations: Default::default(), #[cfg(feature = "artifact-graph")] diff --git a/rust/kcl-lib/src/execution/mod.rs b/rust/kcl-lib/src/execution/mod.rs index 6ec42972d..fca4c06f1 100644 --- a/rust/kcl-lib/src/execution/mod.rs +++ b/rust/kcl-lib/src/execution/mod.rs @@ -823,6 +823,7 @@ impl ExecutorContext { KclErrorWithOutputs::new( err, + exec_state.errors().to_vec(), #[cfg(feature = "artifact-graph")] exec_state.global.operations.clone(), #[cfg(feature = "artifact-graph")] @@ -999,6 +1000,7 @@ impl ExecutorContext { return Err(KclErrorWithOutputs::new( e, + exec_state.errors().to_vec(), #[cfg(feature = "artifact-graph")] exec_state.global.operations.clone(), #[cfg(feature = "artifact-graph")] @@ -1048,6 +1050,7 @@ impl ExecutorContext { KclErrorWithOutputs::new( err, + exec_state.errors().to_vec(), #[cfg(feature = "artifact-graph")] exec_state.global.operations.clone(), #[cfg(feature = "artifact-graph")] @@ -1100,6 +1103,7 @@ impl ExecutorContext { KclErrorWithOutputs::new( e, + exec_state.errors().to_vec(), #[cfg(feature = "artifact-graph")] exec_state.global.operations.clone(), #[cfg(feature = "artifact-graph")] diff --git a/src/lang/errors.test.ts b/src/lang/errors.test.ts index 41393830b..de7e59531 100644 --- a/src/lang/errors.test.ts +++ b/src/lang/errors.test.ts @@ -12,6 +12,7 @@ describe('test kclErrToDiagnostic', () => { kind: 'semantic', msg: 'Semantic error', sourceRange: topLevelRange(0, 1), + nonFatal: [], operations: [], artifactCommands: [], artifactGraph: defaultArtifactGraph(), @@ -24,6 +25,7 @@ describe('test kclErrToDiagnostic', () => { kind: 'type', msg: 'Type error', sourceRange: topLevelRange(4, 5), + nonFatal: [], operations: [], artifactCommands: [], artifactGraph: defaultArtifactGraph(), diff --git a/src/lang/errors.ts b/src/lang/errors.ts index 80c829673..30c27b389 100644 --- a/src/lang/errors.ts +++ b/src/lang/errors.ts @@ -24,6 +24,7 @@ export class KCLError extends Error { kind: ExtractKind | 'name' sourceRange: SourceRange msg: string + nonFatal: CompilationError[] operations: Operation[] artifactCommands: ArtifactCommand[] artifactGraph: ArtifactGraph @@ -34,6 +35,7 @@ export class KCLError extends Error { kind: ExtractKind | 'name', msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[] = [], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -44,6 +46,7 @@ export class KCLError extends Error { this.kind = kind this.msg = msg this.sourceRange = sourceRange + this.nonFatal = nonFatal this.operations = operations this.artifactCommands = artifactCommands this.artifactGraph = artifactGraph @@ -57,6 +60,7 @@ export class KCLLexicalError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -67,6 +71,7 @@ export class KCLLexicalError extends KCLError { 'lexical', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -81,6 +86,7 @@ export class KCLInternalError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -91,6 +97,7 @@ export class KCLInternalError extends KCLError { 'internal', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -105,6 +112,7 @@ export class KCLSyntaxError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -115,6 +123,7 @@ export class KCLSyntaxError extends KCLError { 'syntax', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -129,6 +138,7 @@ export class KCLSemanticError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -139,6 +149,7 @@ export class KCLSemanticError extends KCLError { 'semantic', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -153,6 +164,7 @@ export class KCLTypeError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -163,6 +175,7 @@ export class KCLTypeError extends KCLError { 'type', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -177,6 +190,7 @@ export class KCLIoError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -187,6 +201,7 @@ export class KCLIoError extends KCLError { 'io', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -201,6 +216,7 @@ export class KCLUnexpectedError extends KCLError { constructor( msg: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -211,6 +227,7 @@ export class KCLUnexpectedError extends KCLError { 'unexpected', msg, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -225,6 +242,7 @@ export class KCLValueAlreadyDefined extends KCLError { constructor( key: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -235,6 +253,7 @@ export class KCLValueAlreadyDefined extends KCLError { 'name', `Key ${key} was already defined elsewhere`, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -249,6 +268,7 @@ export class KCLUndefinedValueError extends KCLError { constructor( key: string, sourceRange: SourceRange, + nonFatal: CompilationError[], operations: Operation[], artifactCommands: ArtifactCommand[], artifactGraph: ArtifactGraph, @@ -259,6 +279,7 @@ export class KCLUndefinedValueError extends KCLError { 'name', `Key ${key} has not been defined`, sourceRange, + nonFatal, operations, artifactCommands, artifactGraph, @@ -286,6 +307,7 @@ export function lspDiagnosticsToKclErrors( [posToOffset(doc, range.start)!, posToOffset(doc, range.end)!, 0], [], [], + [], defaultArtifactGraph(), {}, null @@ -311,9 +333,13 @@ export function lspDiagnosticsToKclErrors( export function kclErrorsToDiagnostics( errors: KCLError[] ): CodeMirrorDiagnostic[] { - return errors + let nonFatal: CodeMirrorDiagnostic[] = [] + const errs = errors ?.filter((err) => isTopLevelModule(err.sourceRange)) - .map((err) => { + .map((err): CodeMirrorDiagnostic => { + if (err.nonFatal.length > 0) { + nonFatal = nonFatal.concat(compilationErrorsToDiagnostics(err.nonFatal)) + } return { from: err.sourceRange[0], to: err.sourceRange[1], @@ -321,6 +347,7 @@ export function kclErrorsToDiagnostics( severity: 'error', } }) + return errs.concat(nonFatal) } export function compilationErrorsToDiagnostics( diff --git a/src/lang/executor.test.ts b/src/lang/executor.test.ts index ded89bc8c..05d296644 100644 --- a/src/lang/executor.test.ts +++ b/src/lang/executor.test.ts @@ -463,6 +463,7 @@ theExtrude = startSketchOn(XY) expect.any(Object), expect.any(Object), expect.any(Object), + expect.any(Object), null ) ) diff --git a/src/lang/wasm.test.ts b/src/lang/wasm.test.ts index 9462e19df..d5a88549f 100644 --- a/src/lang/wasm.test.ts +++ b/src/lang/wasm.test.ts @@ -47,11 +47,11 @@ it('formats numbers with units', () => { describe('test errFromErrWithOutputs', () => { it('converts KclErrorWithOutputs to KclError', () => { const blob = - '{"error":{"kind":"internal","sourceRanges":[],"msg":"Cache busted"},"operations":[],"artifactCommands":[],"artifactGraph":{"map":{}},"filenames":{},"sourceFiles":{},"defaultPlanes":null}' + '{"error":{"kind":"internal","sourceRanges":[],"msg":"Cache busted"},"nonFatal":[],"operations":[],"artifactCommands":[],"artifactGraph":{"map":{}},"filenames":{},"sourceFiles":{},"defaultPlanes":null}' const error = errFromErrWithOutputs(blob) const errorStr = JSON.stringify(error) expect(errorStr).toEqual( - '{"kind":"internal","sourceRange":[0,0,0],"msg":"Cache busted","operations":[],"artifactCommands":[],"artifactGraph":{},"filenames":{},"defaultPlanes":null}' + '{"kind":"internal","sourceRange":[0,0,0],"msg":"Cache busted","nonFatal":[],"operations":[],"artifactCommands":[],"artifactGraph":{},"filenames":{},"defaultPlanes":null}' ) }) }) diff --git a/src/lang/wasm.ts b/src/lang/wasm.ts index d6f9ed9e4..c6c521470 100644 --- a/src/lang/wasm.ts +++ b/src/lang/wasm.ts @@ -247,6 +247,7 @@ export const parse = (code: string | Error): ParseResult | Error => { bestSourceRange(parsed), [], [], + [], defaultArtifactGraph(), {}, null @@ -401,6 +402,7 @@ export const errFromErrWithOutputs = (e: any): KCLError => { parsed.error.kind, parsed.error.msg, bestSourceRange(parsed.error), + parsed.nonFatal, parsed.operations, parsed.artifactCommands, rustArtifactGraphToMap(parsed.artifactGraph),