The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Humanize error messages (#63235)
Romeo Van Snick70d8fda6faa6
diff --git a/e2e/test/scenarios/custom-column/custom-column.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column.cy.spec.jsindex fa5f7097650..8c84889363f 100644--- a/e2e/test/scenarios/custom-column/custom-column.cy.spec.js+++ b/e2e/test/scenarios/custom-column/custom-column.cy.spec.js@@ -2542,4 +2542,16 @@ describe("scenarios > question > custom column > aggregation", () => {});});});++ it("should show a custom error when there are no aggregations in a custom aggregation", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("1 + 1");+ H.popover()+ .findByText(+ "Aggregations should contain at least one aggregation function.",+ )+ .should("be.visible");+ });});diff --git a/src/metabase/lib/expression.cljc b/src/metabase/lib/expression.cljcindex 84698778b85..5231bc201ac 100644--- a/src/metabase/lib/expression.cljc+++ b/src/metabase/lib/expression.cljc@@ -2,6 +2,7 @@(:refer-clojure :exclude [+ - * / case coalesce abs time concat replace float mapv some select-keys])(:require[clojure.string :as str]+ [malli.core :as mc][medley.core :as m][metabase.lib.common :as lib.common][metabase.lib.hierarchy :as lib.hierarchy]@@ -517,6 +518,9 @@(def ^:private expression-validator(mr/validator ::lib.schema.expression/expression))+(def ^:private expression-explainer+ (mr/explainer ::lib.schema.expression/expression))+(defn expression-clause?"Returns true if `expression-clause` is indeed an expression clause, false otherwise."[expression-clause]@@ -545,11 +549,11 @@(assoc :lib/expression-name new-name))(assoc opts :name new-name :display-name new-name))))))-(def ^:private aggregation-validator- (mr/validator ::lib.schema.aggregation/aggregation))+(def ^:private aggregation-explainer+ (mr/explainer ::lib.schema.aggregation/aggregation))-(def ^:private filter-validator- (mr/validator ::lib.schema.expression/boolean))+(def ^:private filter-explainer+ (mr/explainer ::lib.schema.expression/boolean))(defn- expression->name[expr]@@ -635,13 +639,22 @@expr :- :anyexpression-position :- [:maybe :int]](binding [lib.schema.expression/*suppress-expression-type-check?* false]- (let [validator (clojure.core/case expression-mode- :expression expression-validator- :aggregation aggregation-validator- :filter filter-validator)]- (or (when-not (validator expr)- {:message (i18n/tru "Types are incompatible.")- :friendly true})+ (let [explainer (clojure.core/case expression-mode+ :expression expression-explainer+ :aggregation aggregation-explainer+ :filter filter-explainer)]+ (or (when-let [explanation (explainer expr)]+ (let [error (first (:errors explanation))+ schema (:schema error)+ props (or (mc/properties schema)+ (mc/type-properties schema))+ error-friendly? (:error/friendly props)+ error-message-or-fn (:error/message props)+ error-message (if (fn? error-message-or-fn) (str (error-message-or-fn)) (str error-message-or-fn))+ fallback-message (i18n/tru "Types are incompatible.")+ message (if error-friendly? error-message fallback-message)]+ {:message message+ :friendly true}))(when-let [dependency-path(when expression-position(clojure.core/case expression-modediff --git a/src/metabase/lib/schema/aggregation.cljc b/src/metabase/lib/schema/aggregation.cljcindex 82cd5e2da08..108b153c1ad 100644--- a/src/metabase/lib/schema/aggregation.cljc+++ b/src/metabase/lib/schema/aggregation.cljc@@ -142,7 +142,8 @@[:and[:ref :metabase.lib.schema.mbql-clause/clause][:fn- {:error/message "Valid aggregation clause"}+ {:error/message #(i18n/tru "Aggregations should contain at least one aggregation function.")+ :error/friendly true}aggregation-expression?]])(mr/def ::aggregations