From af006a63cad7f3aa48b4c534bd2432d5525566c7 Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Mon, 26 Aug 2024 16:35:06 +0530 Subject: [PATCH] fix js execution opening toasts --- .../sagas/ActionExecution/PostMessageSaga.ts | 4 +- .../src/sagas/ActionExecution/errorUtils.ts | 56 ++++++------------- .../ActionExecution/geolocationSaga.test.ts | 4 +- .../sagas/ActionExecution/geolocationSaga.ts | 11 ++-- app/client/src/sagas/EvaluationsSaga.ts | 4 +- app/client/src/sagas/PostEvaluationSagas.ts | 15 +---- 6 files changed, 29 insertions(+), 65 deletions(-) diff --git a/app/client/src/sagas/ActionExecution/PostMessageSaga.ts b/app/client/src/sagas/ActionExecution/PostMessageSaga.ts index d4adb14be72..d9ff09eb85b 100644 --- a/app/client/src/sagas/ActionExecution/PostMessageSaga.ts +++ b/app/client/src/sagas/ActionExecution/PostMessageSaga.ts @@ -1,6 +1,6 @@ import { call, spawn } from "redux-saga/effects"; import { - logActionExecutionError, + showToastOnExecutionError, TriggerFailureError, } from "sagas/ActionExecution/errorUtils"; import { isEmpty } from "lodash"; @@ -35,6 +35,6 @@ export function* executePostMessage( } } } catch (error) { - yield call(logActionExecutionError, (error as Error).message, true); + yield call(showToastOnExecutionError, (error as Error).message); } } diff --git a/app/client/src/sagas/ActionExecution/errorUtils.ts b/app/client/src/sagas/ActionExecution/errorUtils.ts index 4b142364a63..6fccd50264e 100644 --- a/app/client/src/sagas/ActionExecution/errorUtils.ts +++ b/app/client/src/sagas/ActionExecution/errorUtils.ts @@ -55,35 +55,7 @@ export class ActionValidationError extends TriggerFailureError { } } -export function* logActionExecutionError( - errorMessage: string, - isExecuteJSFunc = true, -) { - //Commenting as per decision taken for the error hanlding epic to not show the trigger errors in the debugger. - // if (triggerPropertyName) { - // AppsmithConsole.addErrors([ - // { - // payload: { - // id: `${source?.id}-${triggerPropertyName}`, - // logType: LOG_TYPE.TRIGGER_EVAL_ERROR, - // text: createMessage(DEBUGGER_TRIGGER_ERROR, triggerPropertyName), - // source: { - // type: ENTITY_TYPE.WIDGET, - // id: source?.id ?? "", - // name: source?.name ?? "", - // propertyPath: triggerPropertyName, - // }, - // messages: [ - // { - // type: errorType, - // message: { name: "TriggerExecutionError", message: errorMessage }, - // }, - // ], - // }, - // }, - // ]); - // } - +export function* showToastOnExecutionError(errorMessage: string) { function onDebugClick() { const appMode = getAppMode(store.getState()); if (appMode === "PUBLISHED") return null; @@ -95,16 +67,22 @@ export function* logActionExecutionError( store.dispatch(setDebuggerSelectedTab(DEBUGGER_TAB_KEYS.ERROR_TAB)); } - if (isExecuteJSFunc) - // This is the toast that is rendered when any unhandled error occurs in JS object. - yield call(showToast, errorMessage, { - kind: "error", - action: { - text: "debug", - effect: () => onDebugClick(), - className: "t--toast-debug-button", - }, - }); + // This is the toast that is rendered when any unhandled error occurs in JS object. + yield call(showToast, errorMessage, { + kind: "error", + action: { + text: "debug", + effect: () => onDebugClick(), + className: "t--toast-debug-button", + }, + }); +} + +export function* showDebuggerOnExecutionError() { + const appMode = getAppMode(store.getState()); + if (appMode === "PUBLISHED") return null; + store.dispatch(showDebugger(true)); + store.dispatch(setDebuggerSelectedTab(DEBUGGER_TAB_KEYS.ERROR_TAB)); } /* diff --git a/app/client/src/sagas/ActionExecution/geolocationSaga.test.ts b/app/client/src/sagas/ActionExecution/geolocationSaga.test.ts index bd846d2b0a7..a2341bb1735 100644 --- a/app/client/src/sagas/ActionExecution/geolocationSaga.test.ts +++ b/app/client/src/sagas/ActionExecution/geolocationSaga.test.ts @@ -5,7 +5,7 @@ import { getUserLocation, } from "./geolocationSaga"; import { setUserCurrentGeoLocation } from "actions/browserRequestActions"; -import { logActionExecutionError } from "./errorUtils"; +import { showToastOnExecutionError } from "./errorUtils"; const mockFn = jest.fn(); @@ -86,7 +86,7 @@ describe("getCurrentLocationSaga", () => { expect(iter.next().value).toHaveProperty( "payload.fn", - logActionExecutionError, + showToastOnExecutionError, ); expect(iter.next().done).toBe(true); }); diff --git a/app/client/src/sagas/ActionExecution/geolocationSaga.ts b/app/client/src/sagas/ActionExecution/geolocationSaga.ts index a47e59cf06d..e0e6bc7db5c 100644 --- a/app/client/src/sagas/ActionExecution/geolocationSaga.ts +++ b/app/client/src/sagas/ActionExecution/geolocationSaga.ts @@ -1,7 +1,7 @@ import type { EventType } from "constants/AppsmithActionConstants/ActionConstants"; import type { TriggerMeta } from "ee/sagas/ActionExecution/ActionExecutionSagas"; import { call, put, spawn, take } from "redux-saga/effects"; -import { logActionExecutionError } from "sagas/ActionExecution/errorUtils"; +import { showToastOnExecutionError } from "sagas/ActionExecution/errorUtils"; import { setUserCurrentGeoLocation } from "actions/browserRequestActions"; import type { Channel } from "redux-saga"; import { channel } from "redux-saga"; @@ -107,7 +107,7 @@ function* errorCallbackHandler(triggerMeta: TriggerMeta, listenerId?: string) { { error: sanitizeGeolocationError(error) }, listenerId, ); - yield call(logActionExecutionError, error.message, true); + yield call(showToastOnExecutionError, error.message); } } @@ -122,7 +122,7 @@ export function* getCurrentLocationSaga(action: TGetGeoLocationDescription) { yield put(setUserCurrentGeoLocation(currentLocation)); return currentLocation; } catch (error) { - yield call(logActionExecutionError, (error as Error).message, true); + yield call(showToastOnExecutionError, (error as Error).message); if (error instanceof GeolocationPositionError) { const sanitizedError = sanitizeGeolocationError(error); throw new GeoLocationError(sanitizedError.message, [sanitizedError]); @@ -141,9 +141,8 @@ export function* watchCurrentLocation( // When a watch is already active, we will not start a new watch. // at a given point in time, only one watch is active yield call( - logActionExecutionError, + showToastOnExecutionError, "A watchLocation is already active. Clear it before before starting a new one", - true, ); return; @@ -171,7 +170,7 @@ export function* watchCurrentLocation( export function* stopWatchCurrentLocation() { if (watchId === undefined) { - yield call(logActionExecutionError, "No location watch active", true); + yield call(showToastOnExecutionError, "No location watch active"); return; } navigator.geolocation.clearWatch(watchId); diff --git a/app/client/src/sagas/EvaluationsSaga.ts b/app/client/src/sagas/EvaluationsSaga.ts index 51c59541321..a5a9cb74cd7 100644 --- a/app/client/src/sagas/EvaluationsSaga.ts +++ b/app/client/src/sagas/EvaluationsSaga.ts @@ -48,7 +48,6 @@ import { } from "actions/evaluationActions"; import ConfigTreeActions from "utils/configTree"; import { - dynamicTriggerErrorHandler, handleJSFunctionExecutionErrorLog, logJSVarCreatedEvent, logSuccessfulBindings, @@ -111,6 +110,7 @@ import { evalErrorHandler } from "./EvalErrorHandler"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { endSpan, startRootSpan } from "UITelemetry/generateTraces"; import { transformTriggerEvalErrors } from "ee/sagas/helpers"; +import { showDebuggerOnExecutionError } from "./ActionExecution/errorUtils"; const APPSMITH_CONFIGS = getAppsmithConfigs(); export const evalWorker = new GracefulWorkerService( @@ -350,7 +350,7 @@ export function* evaluateAndExecuteDynamicTrigger( errors, ); - yield call(dynamicTriggerErrorHandler, transformedErrors); + yield fork(showDebuggerOnExecutionError); yield fork(logDynamicTriggerExecution, { dynamicTrigger, errors: transformedErrors, diff --git a/app/client/src/sagas/PostEvaluationSagas.ts b/app/client/src/sagas/PostEvaluationSagas.ts index a20413dbee9..20017ca5c56 100644 --- a/app/client/src/sagas/PostEvaluationSagas.ts +++ b/app/client/src/sagas/PostEvaluationSagas.ts @@ -20,7 +20,7 @@ import type { EvaluationError } from "utils/DynamicBindingUtils"; import { getEvalErrorPath } from "utils/DynamicBindingUtils"; import { find, get, some } from "lodash"; import LOG_TYPE from "entities/AppsmithConsole/logtype"; -import { call, put, select } from "redux-saga/effects"; +import { put, select } from "redux-saga/effects"; import type { AnyReduxAction } from "ee/constants/ReduxActionConstants"; import AppsmithConsole from "utils/AppsmithConsole"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; @@ -35,7 +35,6 @@ import { isWidgetPropertyNamePath } from "utils/widgetEvalUtils"; import type { ActionEntityConfig } from "ee/entities/DataTree/types"; import type { SuccessfulBindings } from "utils/SuccessfulBindingsMap"; import SuccessfulBindingMap from "utils/SuccessfulBindingsMap"; -import { logActionExecutionError } from "./ActionExecution/errorUtils"; import { getCurrentWorkspaceId } from "ee/selectors/selectedWorkspaceSelectors"; import { getInstanceId } from "ee/selectors/tenantSelectors"; import type { EvalTreeResponseData } from "workers/Evaluation/types"; @@ -57,18 +56,6 @@ export function* logJSVarCreatedEvent( }); } -// TODO: Fix this the next time the file is edited -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function* dynamicTriggerErrorHandler(errors: any[]) { - if (errors.length > 0) { - for (const error of errors) { - const errorMessage = - error.errorMessage.message.message || error.errorMessage.message; - yield call(logActionExecutionError, errorMessage, true); - } - } -} - export function* logSuccessfulBindings( unEvalTree: UnEvalTree, dataTree: DataTree,