Collect structured errors from parsing/executing KCL (#187)

Currently, syntax/semantic errors in the user's source code result in vanilla JS exceptions being thrown, so they show up in the console. Instead, this PR:

- Adds a new type KCLError
- KCL syntax/semantic errors when parsing/executing the source code now throw KCLErrors instead of vanilla JS exceptions.
- KCL errors are caught and logged to a new "Errors" panel, instead of the browser console.
This commit is contained in:
Adam Chalmers
2023-07-26 14:10:30 -05:00
committed by GitHub
parent 6838e96723
commit 0d010b60e5
7 changed files with 287 additions and 72 deletions

View File

@ -38,3 +38,36 @@ export const Logs = () => {
</div>
)
}
export const KCLErrors = () => {
const { kclErrors } = useStore(({ kclErrors }) => ({
kclErrors,
}))
useEffect(() => {
const element = document.querySelector('.console-tile')
if (element) {
element.scrollTop = element.scrollHeight - element.clientHeight
}
}, [kclErrors])
return (
<div>
<PanelHeader title="KCL Errors" />
<div className="h-full relative">
<div className="absolute inset-0 flex flex-col items-start">
<ReactJsonTypeHack
src={kclErrors}
collapsed={1}
collapseStringsAfterLength={60}
enableClipboard={false}
displayArrayKey={false}
displayDataTypes={false}
displayObjectSize={true}
indentWidth={2}
quotesOnKeys={false}
name={false}
/>
</div>
</div>
</div>
)
}