Skip to content

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

Fixed data app remote sync errors formatting (#84336)

Timofey Kachalov9f1f4c3d9fa0
diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/resource_validation.clj b/enterprise/backend/src/metabase_enterprise/data_apps/resource_validation.clj
index e1a1ba113f8..c0a19e35e90 100644
--- a/enterprise/backend/src/metabase_enterprise/data_apps/resource_validation.clj
+++ b/enterprise/backend/src/metabase_enterprise/data_apps/resource_validation.clj
@@ -253,23 +253,25 @@
(tru "{0} names collection {1}, but the app already has a collection, and a data app''s collection cannot be changed."
manifest-path collection-entity-id))])
(for [{:keys [id entity_id] collection-namespace :namespace} collections
- :let [message (cond
+ :let [path (or (file-of "Collection" entity_id) manifest-path)
+ message (cond
(not= :data-apps (keyword collection-namespace))
- (tru "Collection {0} already exists outside the data-apps namespace, so it can''t become a data app''s collection. Give the app a collection of its own: a new entity ID in data_app.yaml and in the collection''s file."
- entity_id)
+ (tru "{0} defines collection {1}, which already exists outside the data-apps namespace, so it can''t become a data app''s collection. Give the app a collection of its own: a new entity ID in data_app.yaml and in the collection''s file."
+ path entity_id)
(not (owned? id))
- (tru "Collection {0} already exists and is another data app''s collection. Give the app a collection of its own: a new entity ID in data_app.yaml and in the collection''s file."
- entity_id))]
+ (tru "{0} defines collection {1}, which already exists and is another data app''s collection. Give the app a collection of its own: a new entity ID in data_app.yaml and in the collection''s file."
+ path entity_id))]
:when message]
- (problem (or (file-of "Collection" entity_id) manifest-path) message))
+ (problem path message))
(for [[model rows] [["Card" (data-apps.db/cards-by-entity-ids (entity-ids-of "Card"))]
["Action" (data-apps.db/actions-by-entity-ids (entity-ids-of "Action"))]]
{:keys [entity_id collection_id]} rows
- :when (not (in-collection? collection_id))]
- (problem (file-of model entity_id)
- (tru "{0} {1} already exists outside this data app''s collection, so the app can''t load it. Move it back if it belongs to this app."
- model entity_id))))))
+ :when (not (in-collection? collection_id))
+ :let [path (file-of model entity_id)]]
+ (problem path
+ (tru "{0} defines {1} {2}, which already exists outside this data app''s collection, so the app can''t load it. Move it back if it belongs to this app."
+ path model entity_id))))))
(defn- model-of [entity]
(:model (last (:serdes/meta entity))))
@@ -334,8 +336,9 @@
(assoc resource :manifest path))]
(for [[[model entity-id] defined-by] (group-by (juxt :model (comp :entity_id :entity)) resources)
:when (< 1 (count (into #{} (map :manifest) defined-by)))
- {:keys [path]} defined-by]
- (problem path (tru "{0} {1} is defined by more than one data app: {2}." model entity-id (str/join ", " (map :path defined-by)))))))
+ ;; each app that names a collection finds every file of it, so a file can be here once per app
+ :let [paths (distinct (map :path defined-by))]]
+ (problem (first paths) (tru "{0} {1} is defined by more than one data app: {2}." model entity-id (str/join ", " paths))))))
(defn- shared-entity-id-problems
"Two manifests can't carry one entity ID: a load keeps one app, and the other's collection is left with no owner."
@@ -410,17 +413,19 @@
(defn problems
"The problems with the data apps among the entity files `files` (`{:path :entity}`, every entity file of the
- snapshot), each as `{:file :message}`. An app whose resources have a problem can't be loaded as the author meant
- it, so an import that sees one fails naming the file."
+ snapshot), each once, as `{:file :message}` with a message that names the file. An app whose resources have a
+ problem can't be loaded as the author meant it, so an import that sees one fails listing the messages."
[files]
(let [manifests (manifests-among files)
defined (defined-dependencies files)]
- (concat
- (shared-entity-id-problems manifests)
- (shared-slug-problems manifests)
- (taken-slug-problems manifests)
- (shared-collection-problems manifests)
- (shared-resource-problems manifests files)
- (child-collection-problems manifests files)
- (other-content-problems manifests files)
- (mapcat #(app-problems defined % files) manifests))))
+ (distinct
+ (concat
+ (shared-entity-id-problems manifests)
+ (shared-slug-problems manifests)
+ (taken-slug-problems manifests)
+ (shared-collection-problems manifests)
+ (shared-resource-problems manifests files)
+ (child-collection-problems manifests files)
+ (other-content-problems manifests files)
+ ;; apps that name one collection each find the problems of its files
+ (mapcat #(app-problems defined % files) manifests)))))
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
index 796f6fca94d..ae53b4ba66c 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj
@@ -144,7 +144,7 @@
;; the validator names a file, whose path may hold any word the matches below look for
(= (:error (ex-data e)) :metabase-enterprise.remote-sync.source.ingestable/invalid-data-app-files)
- (str "Failed to reload from git repository: " message)
+ (str "Failed to reload from git repository. " message)
(str/includes? message "Authentication failed")
"Authentication failed: Please check your git credentials"
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/source/ingestable.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/source/ingestable.clj
index 6820e7b2dca..1940b937d29 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/source/ingestable.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/source/ingestable.clj
@@ -50,8 +50,7 @@
{:path path :entity entity}))
problems (data-apps/problems files)]
(when (seq problems)
- (throw (ex-info (str/join " " (map (fn [{:keys [file message]}] (format "Invalid data app file %s: %s" file message))
- problems))
+ (throw (ex-info (str/join "\n" (cons "Invalid data app files:" (map #(str "- " (:message %)) problems)))
{:files (mapv :file problems) :error ::invalid-data-app-files})))
(doseq [{:keys [file message]} (data-apps/warnings files)]
(log/warnf "Data app file %s: %s" file message))))
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/resource_validation_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/resource_validation_test.clj
index b006859d092..4d39f5d9b49 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/resource_validation_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/resource_validation_test.clj
@@ -148,19 +148,28 @@
(testing "an action outside the app's collection isn't the app's, so it isn't checked as its resource"
(is (= [] (messages (edit-file (shop resources) action-path #(assoc % :collection_id "elsewhere0000000000a" :model_id model-eid))))))))))
+(defn- names-its-file?
+ "Whether each problem of `tree` names its file in its message, which a pull lists alone."
+ [tree]
+ (every? (fn [{:keys [file message]}] (str/includes? message file))
+ (data-apps/problems (files tree))))
+
(deftest refuses-what-this-app-does-not-own-test
(testing "serialization would update any row carrying an entity ID a file names, so a file may only name the app's own"
(testing "a card whose entity ID belongs to a card elsewhere"
(mt/with-temp [:model/Card _ {:name "Someone else's" :entity_id question-eid}]
- (is (some #(str/includes? % (str "Card " question-eid " already exists outside")) (messages (shop (question-resources)))))))
+ (is (some #(str/includes? % (str "Card " question-eid ", which already exists outside")) (messages (shop (question-resources)))))
+ (is (names-its-file? (shop (question-resources))))))
(testing "a collection that is another app's"
(mt/with-temp [:model/Collection {collection-id :id} {:entity_id collection-eid :name "Theirs" :namespace :data-apps}
:model/DataApp _ {:name "theirs" :display_name "Theirs" :bundle_path "index.js"
:resource_collection_id collection-id}]
- (is (some #(str/includes? % "already exists and is another data app's collection") (messages (shop (question-resources)))))))
+ (is (some #(str/includes? % "already exists and is another data app's collection") (messages (shop (question-resources)))))
+ (is (names-its-file? (shop (question-resources))))))
(testing "a collection outside the data-apps namespace, which a load would move into it"
(mt/with-temp [:model/Collection _ {:entity_id collection-eid :name "Finance"}]
- (is (some #(str/includes? % "already exists outside the data-apps namespace") (messages (shop (question-resources)))))))
+ (is (some #(str/includes? % "already exists outside the data-apps namespace") (messages (shop (question-resources)))))
+ (is (names-its-file? (shop (question-resources))))))
(testing "the app's own collection and card"
(mt/with-temp [:model/Collection {collection-id :id} {:entity_id collection-eid :name "Mine" :namespace :data-apps}
:model/DataApp _ {:name "shop" :display_name "Shop" :bundle_path "index.js"
@@ -374,6 +383,13 @@
"data_apps/shop2/data_app.yaml" #(assoc % :slug "shop")))]
(is (= 2 (count (filter #(str/includes? % "has the slug") (messages tree))))))))
+(deftest lists-a-problem-two-apps-find-once-test
+ (testing "two apps that name one collection each find the problems of its files, which are listed once"
+ (let [app (fn [slug] (data-apps.tu/app-files slug {:name slug :path "index.js" :bundle "B" :collection collection-eid}))
+ found (messages (merge (app "first") (app "second")))]
+ (is (= 1 (count (filter #(str/includes? % "is defined by more than one file") found))))
+ (is (apply distinct? found)))))
+
(deftest refuses-other-content-in-the-apps-collection-test
(testing "a data app's collection holds cards and actions only, and a load would refuse anything else only after it
had started"
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
index e44a94e268e..41a684febd1 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
@@ -507,10 +507,25 @@
(is (= :error (:status result)))
(is (str/includes? (:message result) "data_apps/first/data_app.yaml"))
(is (str/includes? (:message result) "data_apps/second/data_app.yaml"))
+ (testing "a problem both apps find in the collection they share is listed once"
+ (is (apply distinct? (str/split-lines (:message result)))))
(testing "nothing loaded"
(is (not (t2/exists? :model/DataApp :name [:in ["first" "second"]])))
(is (not (t2/exists? :model/Collection :entity_id shared)))))))
+(deftest pull-lists-each-problem-on-its-own-line-test
+ (testing "a pull refusing several apps names each problem's file once, one problem per line"
+ (with-data-apps-sync
+ (let [app (fn [slug] (data-apps.tu/app-files slug {:name slug :path "index.js" :bundle "B" :collection nil}))
+ src (test-helpers/versioned-source :trees {"v0" (merge (app "first") (app "second"))} :current "v0")
+ result (import-at! src "v0" :force? true)
+ [lead & problems] (str/split-lines (:message result))]
+ (is (= :error (:status result)))
+ (is (= "Failed to reload from git repository. Invalid data app files:" lead))
+ (is (= ["- data_apps/first/data_app.yaml must name the app's resource collection as `collection`."
+ "- data_apps/second/data_app.yaml must name the app's resource collection as `collection`."]
+ (sort problems)))))))
+
(deftest pull-refuses-two-apps-that-define-one-card-test
(with-data-apps-sync
(let [app (fn [slug]
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.tsx
index 53fe888bc55..7b7b728cfcf 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.tsx
@@ -85,7 +85,9 @@ export function SyncProgressModal({
<Modal onClose={onDismiss} opened size="md" title={t`Sync failed`}>
<Stack mt="lg" gap="lg">
<Text>{t`An error occurred during sync.`}</Text>
- {errorMessage && <Text>{errorMessage}</Text>}
+ {errorMessage && (
+ <Text style={{ whiteSpace: "pre-line" }}>{errorMessage}</Text>
+ )}
{startedBy}
<Group justify="flex-end">
<Button
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.unit.spec.tsx
index e891b9ac17b..25831e81673 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncProgressModal.unit.spec.tsx
@@ -279,6 +279,21 @@ describe("SyncProgressModal", () => {
expect(screen.getByText("Connection timeout")).toBeInTheDocument();
});
+ it("should keep the line breaks of a multi-line message", () => {
+ const errorMessage = [
+ "Failed to reload from git repository. Invalid data app files:",
+ "- data_apps/first/data_app.yaml must name the app's resource collection as `collection`.",
+ "- data_apps/second/data_app.yaml must name the app's resource collection as `collection`.",
+ ].join("\n");
+ setup({ isError: true, errorMessage });
+
+ const message = screen.getByText(/Invalid data app files:/);
+ expect(message).toHaveTextContent(errorMessage, {
+ normalizeWhitespace: false,
+ });
+ expect(message).toHaveStyle({ whiteSpace: "pre-line" });
+ });
+
it("should show close button in error state", () => {
setup({ isError: true });