mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
[Bugfix] Syntax Errors in Query Transformation and adds them to the Debugger (#3757)
* handles syntax and reference error for js for query transformations * fixes toast description for errors from query transformation
This commit is contained in:
parent
8fd356926b
commit
1a4ab8d0e6
1 changed files with 18 additions and 4 deletions
|
|
@ -18,6 +18,15 @@ import { v4 as uuidv4 } from 'uuid';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import { allSvgs } from '@tooljet/plugins/client';
|
import { allSvgs } from '@tooljet/plugins/client';
|
||||||
|
|
||||||
|
const ERROR_TYPES = Object.freeze({
|
||||||
|
ReferenceError: 'ReferenceError',
|
||||||
|
SyntaxError: 'SyntaxError',
|
||||||
|
TypeError: 'TypeError',
|
||||||
|
URIError: 'URIError',
|
||||||
|
RangeError: 'RangeError',
|
||||||
|
EvalError: 'EvalError',
|
||||||
|
});
|
||||||
|
|
||||||
export function setStateAsync(_ref, state) {
|
export function setStateAsync(_ref, state) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
_ref.setState(state, resolve);
|
_ref.setState(state, resolve);
|
||||||
|
|
@ -75,15 +84,17 @@ export function getDataFromLocalStorage(key) {
|
||||||
|
|
||||||
export function runTransformation(_ref, rawData, transformation, query) {
|
export function runTransformation(_ref, rawData, transformation, query) {
|
||||||
const data = rawData;
|
const data = rawData;
|
||||||
const evalFunction = Function(
|
|
||||||
['data', 'moment', '_', 'components', 'queries', 'globals', 'variables'],
|
|
||||||
transformation
|
|
||||||
);
|
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
const currentState = _ref.state.currentState || {};
|
const currentState = _ref.state.currentState || {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const evalFunction = Function(
|
||||||
|
['data', 'moment', '_', 'components', 'queries', 'globals', 'variables'],
|
||||||
|
transformation
|
||||||
|
);
|
||||||
|
|
||||||
result = evalFunction(
|
result = evalFunction(
|
||||||
data,
|
data,
|
||||||
moment,
|
moment,
|
||||||
|
|
@ -95,6 +106,9 @@ export function runTransformation(_ref, rawData, transformation, query) {
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Transformation failed for query: ', query.name, err);
|
console.log('Transformation failed for query: ', query.name, err);
|
||||||
|
const $error = err.name;
|
||||||
|
const $errorMessage = _.has(ERROR_TYPES, $error) ? `${$error} : ${err.message}` : err || 'Unknown error';
|
||||||
|
toast.error($errorMessage);
|
||||||
result = { message: err.stack.split('\n')[0], status: 'failed', data: data };
|
result = { message: err.stack.split('\n')[0], status: 'failed', data: data };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue