mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 01:18:23 +00:00
fix: custom debug and transformation entities bugs
This commit is contained in:
parent
d159e5a55c
commit
27c32cc12b
4 changed files with 67 additions and 37 deletions
|
|
@ -470,7 +470,7 @@ export const createEventsSlice = (set, get) => ({
|
|||
error: {
|
||||
message: error.message,
|
||||
description: JSON.stringify(error.message, null, 2),
|
||||
...(event.component && componentId && { componentId: componentId }),
|
||||
...(event.component === 'component' && componentId && { componentId: componentId }),
|
||||
},
|
||||
errorTarget: constructErrorTarget(),
|
||||
options: options,
|
||||
|
|
|
|||
|
|
@ -425,7 +425,7 @@ export const createQueryPanelSlice = (set, get) => ({
|
|||
query,
|
||||
'edit'
|
||||
);
|
||||
if (finalData.status === 'failed') {
|
||||
if (finalData?.status === 'failed') {
|
||||
setResolvedQuery(queryId, {
|
||||
isLoading: false,
|
||||
});
|
||||
|
|
@ -749,18 +749,30 @@ export const createQueryPanelSlice = (set, get) => ({
|
|||
runTransformation: async (rawData, transformation, transformationLanguage = 'javascript', query, mode = 'edit') => {
|
||||
const data = rawData;
|
||||
const {
|
||||
queryPanel: { runPythonTransformation },
|
||||
queryPanel: { runPythonTransformation, createProxy },
|
||||
getResolvedState,
|
||||
} = get();
|
||||
let result = [];
|
||||
let result = {};
|
||||
const currentState = getResolvedState();
|
||||
|
||||
if (transformationLanguage === 'python') {
|
||||
result = await runPythonTransformation(currentState, data, transformation, query, mode);
|
||||
} else if (transformationLanguage === 'javascript') {
|
||||
try {
|
||||
const { eventsSlice } = get();
|
||||
const { generateAppActions } = eventsSlice;
|
||||
const queriesInResolvedState = deepClone(currentState.queries);
|
||||
const actions = generateAppActions('', mode);
|
||||
|
||||
const proxiedComponents = createProxy(currentState?.components, 'components');
|
||||
const proxiedGlobals = createProxy(currentState?.globals, 'globals');
|
||||
const proxiedConstants = createProxy(currentState?.constants, 'constants');
|
||||
const proxiedVariables = createProxy(currentState?.variables, 'variables');
|
||||
const proxiedPage = createProxy(deepClone(currentState?.page, 'page'));
|
||||
const proxiedQueriesInResolvedState = createProxy(queriesInResolvedState, 'queries');
|
||||
|
||||
const evalFunction = Function(
|
||||
['data', 'moment', '_', 'components', 'queries', 'globals', 'variables', 'page', 'constants'],
|
||||
['data', 'moment', '_', 'components', 'queries', 'globals', 'variables', 'page', 'constants', 'actions'],
|
||||
transformation
|
||||
);
|
||||
|
||||
|
|
@ -768,32 +780,45 @@ export const createQueryPanelSlice = (set, get) => ({
|
|||
data,
|
||||
moment,
|
||||
_,
|
||||
currentState.components,
|
||||
currentState.queries,
|
||||
currentState.globals,
|
||||
currentState.variables,
|
||||
currentState.page,
|
||||
currentState.constants
|
||||
proxiedComponents,
|
||||
proxiedQueriesInResolvedState,
|
||||
proxiedGlobals,
|
||||
proxiedVariables,
|
||||
proxiedPage,
|
||||
proxiedConstants,
|
||||
{
|
||||
logError: actions.logError,
|
||||
logInfo: actions.logInfo,
|
||||
log: actions.log,
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
result = {
|
||||
message: err.stack.split('\n')[0],
|
||||
status: 'failed',
|
||||
data: data,
|
||||
};
|
||||
const stackLines = err.stack.split('\n');
|
||||
const errorLocation =
|
||||
stackLines[2]?.match(/<anonymous>:(\d+):(\d+)/) ?? stackLines[1]?.match(/<anonymous>:(\d+):(\d+)/);
|
||||
|
||||
let lineNumber = null;
|
||||
|
||||
if (errorLocation) {
|
||||
lineNumber = errorLocation[1] - 2;
|
||||
}
|
||||
|
||||
console.log('JS execution failed: ', err);
|
||||
let error = err.message || err.stack.split('\n')[0] || 'JS execution failed';
|
||||
result = { status: 'failed', data: { message: error, description: error, lineNumber } };
|
||||
get().debugger.log({
|
||||
logLevel: result?.status === 'failed' ? 'error' : 'success',
|
||||
type: 'transformation',
|
||||
kind: query.kind,
|
||||
key: query.name,
|
||||
message: result?.message,
|
||||
error: result?.data,
|
||||
isTransformation: true,
|
||||
isQuerySuccessLog: result?.status === 'failed' ? false : true,
|
||||
errorTarget: 'Queries',
|
||||
});
|
||||
}
|
||||
}
|
||||
get().debugger.log({
|
||||
logLevel: result?.status === 'failed' ? 'error' : 'success',
|
||||
type: 'transformation',
|
||||
kind: query.kind,
|
||||
key: query.name,
|
||||
message: result?.message,
|
||||
error: result,
|
||||
isTransformation: true,
|
||||
isQuerySuccessLog: result?.status === 'failed' ? false : true,
|
||||
errorTarget: 'Queries',
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
|
|
@ -861,12 +886,13 @@ export const createQueryPanelSlice = (set, get) => ({
|
|||
createProxy: (obj, path = '') => {
|
||||
const { queryPanel } = get();
|
||||
const { createProxy } = queryPanel;
|
||||
|
||||
return new Proxy(obj, {
|
||||
get(target, prop) {
|
||||
const fullPath = path ? `${path}.${prop}` : prop;
|
||||
|
||||
if (!(prop in target)) {
|
||||
throw new Error(`Property "${fullPath}" is not defined`);
|
||||
throw new Error(`ReferenceError: ${fullPath} is not defined`);
|
||||
}
|
||||
|
||||
const value = target[prop];
|
||||
|
|
@ -955,13 +981,16 @@ export const createQueryPanelSlice = (set, get) => ({
|
|||
|
||||
//Proxy Func required to get current execution line number from stack to log in debugger
|
||||
|
||||
const proxiedComponents = createProxy(resolvedState?.components);
|
||||
const proxiedGlobals = createProxy(resolvedState?.globals);
|
||||
const proxiedConstants = createProxy(resolvedState?.constants);
|
||||
const proxiedVariables = createProxy(resolvedState?.variables);
|
||||
const proxiedPage = createProxy(deepClone(resolvedState?.page));
|
||||
const proxiedQueriesInResolvedState = createProxy(queriesInResolvedState);
|
||||
const proxiedFormattedParams = createProxy(!_.isEmpty(proxiedFormattedParams) ? [proxiedFormattedParams] : []);
|
||||
const proxiedComponents = createProxy(resolvedState?.components, 'components');
|
||||
const proxiedGlobals = createProxy(resolvedState?.globals, 'globals');
|
||||
const proxiedConstants = createProxy(resolvedState?.constants, 'constants');
|
||||
const proxiedVariables = createProxy(resolvedState?.variables, 'variables');
|
||||
const proxiedPage = createProxy(deepClone(resolvedState?.page, 'page'));
|
||||
const proxiedQueriesInResolvedState = createProxy(queriesInResolvedState, 'queries');
|
||||
const proxiedFormattedParams = createProxy(
|
||||
!_.isEmpty(proxiedFormattedParams) ? [proxiedFormattedParams] : [],
|
||||
'params'
|
||||
);
|
||||
|
||||
const fnParams = [
|
||||
'moment',
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ function Logs({ logProps, idx }) {
|
|||
logProps?.description ||
|
||||
(isString(logProps?.message) && logProps?.message) ||
|
||||
(isString(logProps?.error?.description) && logProps?.error?.description) || //added string check since description can be an object. eg: runpy
|
||||
logProps?.error?.message.trim()
|
||||
logProps?.error?.message
|
||||
}`;
|
||||
|
||||
const defaultStyles = {
|
||||
|
|
@ -113,7 +113,7 @@ function Logs({ logProps, idx }) {
|
|||
</span>
|
||||
</div>
|
||||
<span
|
||||
className={cx('mx-1', {
|
||||
className={cx({
|
||||
'text-tomato-9': !logProps?.isQuerySuccessLog,
|
||||
'color-light-green': logProps?.isQuerySuccessLog,
|
||||
})}
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@
|
|||
|
||||
.text-tomato-9 {
|
||||
color: var(--tomato9);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.text-slate-10 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue