Ensure exceptions in the executor are handled properly (#239)

Right now, if the executor throws a KCLError (e.g. for "variable name is not defined" errors), they aren't being caught by the .catch or the try/catch block in asyncWrap. This PR fixes it.

Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
Adam Chalmers
2023-08-07 20:33:38 -05:00
committed by GitHub
parent 7a537eea8e
commit a986f76e70
3 changed files with 49 additions and 36 deletions

View File

@ -6,6 +6,7 @@ import { ProgramMemory, Path, SketchGroup } from './executor'
import { initPromise } from './rust'
import { enginelessExecutor } from '../lib/testHelpers'
import { vi } from 'vitest'
import { KCLUndefinedValueError } from './errors'
beforeAll(() => initPromise)
@ -440,6 +441,22 @@ describe('testing math operators', () => {
})
})
describe('Testing Errors', () => {
it('should throw an error when a variable is not defined', async () => {
const code = `const myVar = 5
const theExtrude = startSketchAt([0, 0])
|> line([-2.4, 5], %)
|> line([-0.76], myVarZ, %)
|> line([5,5], %)
|> close(%)
|> extrude(4, %)
show(theExtrude)`
await expect(exe(code)).rejects.toEqual(
new KCLUndefinedValueError('Memory item myVarZ not found', [[100, 106]])
)
})
})
// helpers
async function exe(