Add toast for trigger errors (#3100)

This commit is contained in:
Hetu Nandu 2021-02-22 10:30:16 +05:30 committed by GitHub
parent 03eba7ed27
commit 88c86fa881
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 25 deletions

View File

@ -15,16 +15,16 @@ import {
} from "constants/ReduxActionConstants";
import { getUnevaluatedDataTree } from "selectors/dataTreeSelectors";
import WidgetFactory, { WidgetTypeConfigMap } from "../utils/WidgetFactory";
import { GracefulWorkerService } from "../utils/WorkerUtil";
import { GracefulWorkerService } from "utils/WorkerUtil";
import Worker from "worker-loader!../workers/evaluation.worker";
import {
EVAL_WORKER_ACTIONS,
EvalError,
EvalErrorTypes,
} from "../utils/DynamicBindingUtils";
} from "utils/DynamicBindingUtils";
import log from "loglevel";
import { WidgetType } from "../constants/WidgetConstants";
import { WidgetProps } from "../widgets/BaseWidget";
import { WidgetType } from "constants/WidgetConstants";
import { WidgetProps } from "widgets/BaseWidget";
import PerformanceTracker, {
PerformanceTransactionName,
} from "../utils/PerformanceTracker";
@ -41,22 +41,36 @@ const worker = new GracefulWorkerService(Worker);
const evalErrorHandler = (errors: EvalError[]) => {
if (!errors) return;
errors.forEach((error) => {
if (error.type === EvalErrorTypes.DEPENDENCY_ERROR) {
Toaster.show({
text: error.message,
variant: Variant.danger,
});
switch (error.type) {
case EvalErrorTypes.DEPENDENCY_ERROR: {
Toaster.show({
text: error.message,
variant: Variant.danger,
});
break;
}
case EvalErrorTypes.EVAL_TREE_ERROR: {
Toaster.show({
text: "Unexpected error occurred while evaluating the app",
variant: Variant.danger,
});
break;
}
case EvalErrorTypes.BAD_UNEVAL_TREE_ERROR: {
Sentry.captureException(error);
break;
}
case EvalErrorTypes.EVAL_TRIGGER_ERROR: {
Toaster.show({
text: `Error occurred when executing trigger: ${error.message}`,
variant: Variant.danger,
});
break;
}
default: {
Sentry.captureException(error);
}
}
if (error.type === EvalErrorTypes.EVAL_TREE_ERROR) {
Toaster.show({
text: "Unexpected error occurred while evaluating the app",
variant: Variant.danger,
});
}
if (error.type === EvalErrorTypes.BAD_UNEVAL_TREE_ERROR) {
Sentry.captureException(error);
}
log.debug(error);
});
};

View File

@ -5,7 +5,7 @@ import {
} from "constants/BindingsConstants";
import { Action } from "entities/Action";
import moment from "moment-timezone";
import { WidgetProps } from "../widgets/BaseWidget";
import { WidgetProps } from "widgets/BaseWidget";
import parser from "fast-xml-parser";
export type DependencyMap = Record<string, Array<string>>;
@ -91,6 +91,7 @@ export enum EvalErrorTypes {
EVAL_ERROR = "EVAL_ERROR",
UNKNOWN_ERROR = "UNKNOWN_ERROR",
BAD_UNEVAL_TREE_ERROR = "BAD_UNEVAL_TREE_ERROR",
EVAL_TRIGGER_ERROR = "EVAL_TRIGGER_ERROR",
}
export type EvalError = {

View File

@ -19,11 +19,11 @@ import {
isPathADynamicBinding,
isPathADynamicTrigger,
unsafeFunctionForEval,
} from "../utils/DynamicBindingUtils";
} from "utils/DynamicBindingUtils";
import _ from "lodash";
import { WidgetTypeConfigMap } from "../utils/WidgetFactory";
import { WidgetTypeConfigMap } from "utils/WidgetFactory";
import toposort from "toposort";
import { DATA_BIND_REGEX } from "../constants/BindingsConstants";
import { DATA_BIND_REGEX } from "constants/BindingsConstants";
import equal from "fast-deep-equal/es6";
import unescapeJS from "unescape-js";
@ -46,7 +46,7 @@ import {
import {
EXECUTION_PARAM_KEY,
EXECUTION_PARAM_REFERENCE_REGEX,
} from "../constants/ActionConstants";
} from "constants/ActionConstants";
const ctx: Worker = self as any;
@ -152,7 +152,17 @@ ctx.addEventListener(
callbackData,
);
const cleanTriggers = removeFunctions(triggers);
const errors = dataTreeEvaluator.errors;
// Transforming eval errors into eval trigger errors. Since trigger
// errors occur less, we want to treat it separately
const errors = dataTreeEvaluator.errors.map((error) => {
if (error.type === EvalErrorTypes.EVAL_ERROR) {
return {
...error,
type: EvalErrorTypes.EVAL_TRIGGER_ERROR,
};
}
return error;
});
dataTreeEvaluator.clearErrors();
return { triggers: cleanTriggers, errors };
}