Skip to content
Snippets Groups Projects
Unverified Commit 9b305a03 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Add a try-catch for MBQL lib diagnoseExpression (#44628)

parent 1d5d9cb4
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,8 @@ import {
appBar,
openProductsTable,
queryBuilderFooter,
enterCustomColumnDetails,
addCustomColumn,
} from "e2e/support/helpers";
const { ORDERS, ORDERS_ID, PRODUCTS } = SAMPLE_DATABASE;
......@@ -475,6 +477,23 @@ describe("issue 40435", () => {
});
});
describe("issue 41381", () => {
beforeEach(() => {
restore();
cy.signInAsNormalUser();
});
it("should show an error message when adding a constant-only custom expression (metabase#41381)", () => {
openOrdersTable({ mode: "notebook" });
addCustomColumn();
enterCustomColumnDetails({ formula: "'Test'", name: "Constant" });
popover().within(() => {
cy.findByText("Invalid expression").should("be.visible");
cy.button("Done").should("be.disabled");
});
});
});
describe(
"issue 42010 -- Unable to filter by mongo id",
{ tags: "@mongo" },
......
......@@ -144,22 +144,27 @@ export function diagnose({
const expressionMode: Lib.ExpressionMode =
startRuleToExpressionModeMapping[startRule] ?? startRule;
const possibleError = Lib.diagnoseExpression(
query,
stageIndex,
expressionMode,
mbqlOrError,
expressionPosition,
);
if (possibleError) {
console.warn("diagnostic error", possibleError.message);
// diagnoseExpression returns some messages which are user-friendly and some which are not.
// If the `friendly` flag is true, we can use the possibleError as-is; if not then use a generic message.
return possibleError.friendly
? possibleError
: { message: t`Invalid expression` };
try {
const possibleError = Lib.diagnoseExpression(
query,
stageIndex,
expressionMode,
mbqlOrError,
expressionPosition,
);
if (possibleError) {
console.warn("diagnostic error", possibleError.message);
// diagnoseExpression returns some messages which are user-friendly and some which are not.
// If the `friendly` flag is true, we can use the possibleError as-is; if not then use a generic message.
return possibleError.friendly
? possibleError
: { message: t`Invalid expression` };
}
} catch (error) {
console.warn("diagnostic error", error);
return { message: t`Invalid expression` };
}
return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment