Stop throwing in frontend code (#2654)

Return error instead of throw
This commit is contained in:
49fl
2024-06-24 11:45:40 -04:00
committed by GitHub
parent f7196e7eb0
commit f4877cb160
67 changed files with 5127 additions and 4523 deletions

View File

@ -6,6 +6,7 @@ import { PrevVariable, findAllPreviousVariables } from 'lang/queryAst'
import { Value, parse } from 'lang/wasm'
import { useEffect, useRef, useState } from 'react'
import { executeAst } from 'useStore'
import { trap } from 'lib/trap'
const isValidVariableName = (name: string) =>
/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)
@ -85,6 +86,8 @@ export function useCalculateKclExpression({
const execAstAndSetResult = async () => {
const _code = `const __result__ = ${value}`
const ast = parse(_code)
if (trap(ast, { suppress: true })) return
const _programMem: any = { root: {}, return: null }
availableVarInfo.variables.forEach(({ key, value }) => {
_programMem.root[key] = { type: 'userVal', value, __meta: [] }