Skip to content

Commit

Permalink
fix js execution opening toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu committed Aug 26, 2024
1 parent b6eef61 commit af006a6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 65 deletions.
4 changes: 2 additions & 2 deletions app/client/src/sagas/ActionExecution/PostMessageSaga.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { call, spawn } from "redux-saga/effects";
import {
logActionExecutionError,
showToastOnExecutionError,
TriggerFailureError,
} from "sagas/ActionExecution/errorUtils";
import { isEmpty } from "lodash";
Expand Down Expand Up @@ -35,6 +35,6 @@ export function* executePostMessage(
}
}
} catch (error) {
yield call(logActionExecutionError, (error as Error).message, true);
yield call(showToastOnExecutionError, (error as Error).message);
}
}
56 changes: 17 additions & 39 deletions app/client/src/sagas/ActionExecution/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/sagas/ActionExecution/geolocationSaga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -86,7 +86,7 @@ describe("getCurrentLocationSaga", () => {

expect(iter.next().value).toHaveProperty(
"payload.fn",
logActionExecutionError,
showToastOnExecutionError,
);
expect(iter.next().done).toBe(true);
});
Expand Down
11 changes: 5 additions & 6 deletions app/client/src/sagas/ActionExecution/geolocationSaga.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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]);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/sagas/EvaluationsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
} from "actions/evaluationActions";
import ConfigTreeActions from "utils/configTree";
import {
dynamicTriggerErrorHandler,
handleJSFunctionExecutionErrorLog,
logJSVarCreatedEvent,
logSuccessfulBindings,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -350,7 +350,7 @@ export function* evaluateAndExecuteDynamicTrigger(
errors,
);

yield call(dynamicTriggerErrorHandler, transformedErrors);
yield fork(showDebuggerOnExecutionError);
yield fork(logDynamicTriggerExecution, {
dynamicTrigger,
errors: transformedErrors,
Expand Down
15 changes: 1 addition & 14 deletions app/client/src/sagas/PostEvaluationSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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,
Expand Down

0 comments on commit af006a6

Please sign in to comment.