Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Better checker output (#72734)

dpsuttonbcec823dbaa0
diff --git a/enterprise/backend/src/metabase_enterprise/checker/cli.clj b/enterprise/backend/src/metabase_enterprise/checker/cli.clj
index 29e8c3db5c9..9aee40529f8 100644
--- a/enterprise/backend/src/metabase_enterprise/checker/cli.clj
+++ b/enterprise/backend/src/metabase_enterprise/checker/cli.clj
@@ -56,54 +56,39 @@
(fail! (str "--schema-format concise expects a single JSON file, got a directory: " path)
"Did you mean --schema-format serdes?"))))
+(defn- print-human
+ "Print one FAIL block per failing entity, then a one-line summary."
+ [results]
+ (let [failures (->> results
+ (filter #(not= :ok (checker/result-status (second %))))
+ (sort-by (comp :name second)))]
+ (doseq [entry failures
+ :let [block (checker/format-fail entry)]
+ :when block]
+ (output! block)
+ (output!))
+ (output! (format "Ran %d entities, %d failed" (count results) (count failures)))))
+
(defn- run-checker
"Run the semantic checker."
- [export-dir {:keys [output errors-only schema-dir schema-format]}]
+ [export-dir {:keys [output schema-dir schema-format]}]
(when-not schema-dir
(fail! "Missing --schema-dir option"))
- (let [fmt (case schema-format
- "concise" :concise
- "serdes" :serdes
- nil :serdes
- (fail! (str "Unknown --schema-format: " schema-format
- " (must be 'serdes' or 'concise')")))
- _ (validate-schema-path! schema-dir fmt)
+ (let [schema-fmt (case schema-format
+ "concise" :concise
+ "serdes" :serdes
+ nil :serdes
+ (fail! (str "Unknown --schema-format: " schema-format
+ " (must be 'serdes' or 'concise')")))
+ _ (validate-schema-path! schema-dir schema-fmt)
{:keys [results]} (try
- (checker/check export-dir schema-dir nil {:schema-format fmt})
+ (checker/check export-dir schema-dir nil {:schema-format schema-fmt})
(catch clojure.lang.ExceptionInfo e
(fail! (.getMessage e))))
- summary (checker/summarize-results results)
- failures (filter #(not= :ok (checker/result-status (second %))) results)]
- (if errors-only
- ;; Errors-only mode: just errors to stdout, nothing else
- (doseq [entry (sort-by (comp :name second) failures)
- :let [error-str (checker/format-error entry)]
- :when error-str]
- #_{:clj-kondo/ignore [:discouraged-var]}
- (output! error-str))
- ;; Normal mode: full output
- (do
- ;; Write to output file if specified
- (when output
- (spit output (pr-str results))
- (output! "Results written to:" output))
- ;; Print summary
- (output! "Semantic Check Results")
- (output! "=====================")
- (output! "Total entities:" (:total summary))
- (output! " OK:" (:ok summary))
- (output! " Errors:" (:errors summary))
- (output! " Unresolved refs:" (:unresolved summary))
- (output! " Native SQL errors:" (:native-errors summary))
- (output! " Issues:" (:issues summary))
- ;; Print failures
- (when (seq failures)
- (output! "\nFailures:")
- (output! "---------")
- (doseq [entry (sort-by (comp :name second) failures)]
- (output!)
- (output! (checker/format-result entry))))))
- ;; Exit with appropriate code
+ summary (checker/summarize-results results)]
+ (when output
+ (spit output (pr-str results)))
+ (print-human results)
(flush)
(System/exit (if (zero? (+ (:errors summary) (:unresolved summary)
(:native-errors summary) (:issues summary)))
@@ -116,8 +101,7 @@
[nil "--export PATH" "Path to serdes export directory"]
[nil "--schema-dir PATH" "Path to schema source (directory for serdes, JSON file for concise)"]
[nil "--schema-format FMT" "Schema format: 'serdes' (default) or 'concise'"]
- [nil "--output PATH" "Path to output file for results"]
- [nil "--errors-only" "Output only errors to stdout (concise format for LLM consumption)"]
+ [nil "--output PATH" "Path to output file for raw EDN results"]
["-h" "--help" "Show this help"]])
(defn- usage [summary]
diff --git a/enterprise/backend/src/metabase_enterprise/checker/semantic.clj b/enterprise/backend/src/metabase_enterprise/checker/semantic.clj
index 8ddc8ce0c3f..37017f7cb1e 100644
--- a/enterprise/backend/src/metabase_enterprise/checker/semantic.clj
+++ b/enterprise/backend/src/metabase_enterprise/checker/semantic.clj
@@ -691,6 +691,52 @@
:ok " Status: OK"))
(str/join "\n" @lines)))
+(defn- issue-line
+ "Render a single issue as ` - <type>: <detail>`. Skips refs that are nil
+ and uses the first non-empty detail field."
+ [{:keys [type path entity-id name message]}]
+ (let [type-name (clojure.core/name type)
+ type-label (-> type-name
+ (str/replace #"-" " "))
+ detail (or (some->> path (str/join "."))
+ entity-id
+ name
+ message)]
+ (str " - "
+ (case type
+ :duplicate-column (str "duplicate column: " name)
+ :missing-column (str "missing column: " name)
+ :missing-table-alias (str "missing table alias: " name)
+ :syntax-error "syntax error"
+ :validation-exception-error (str "validation error: " message)
+ ;; unresolved-ref types — prefix with "unresolved"
+ (:database :table :field :card :snippet :transform :segment
+ :measure :dashboard :collection :document)
+ (str "unresolved " type-name ": " detail)
+ ;; structural checks (e.g. :dashcard-grid, :container-conflict)
+ (str type-label ": " (or detail ""))))))
+
+(defn format-fail
+ "Format a single failed entity result as a human-readable block.
+ Returns nil for :ok results.
+
+ FAIL <kind> \"<name>\" [<entity-id>]
+ - issue 1
+ - issue 2
+ ..."
+ [[entity-id result]]
+ (let [status (result-status result)]
+ (when (not= :ok status)
+ (let [kind-label (if-let [kind (:kind result)] (clojure.core/name kind) "card")
+ issues (concat (:unresolved result)
+ (:bad-refs result)
+ (:native-errors result)
+ (when-let [err (:error result)]
+ [{:type :error :message err}]))
+ header (str "FAIL " kind-label " \"" (:name result) "\" [" entity-id "]")
+ body (map issue-line issues)]
+ (str/join "\n" (cons header body))))))
+
(defn format-error
"Format a single card error concisely for LLM consumption.
Returns nil for :ok results. Only includes actionable error information."