Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don't fail the dashboard when one section errors (#41720)

Krzysztof Kotlarek87247653e22a
diff --git a/app/assets/stylesheets/admin/admin_dashboard.scss b/app/assets/stylesheets/admin/admin_dashboard.scss
index 46e4601ff6c..b5be78ef13c 100644
--- a/app/assets/stylesheets/admin/admin_dashboard.scss
+++ b/app/assets/stylesheets/admin/admin_dashboard.scss
@@ -212,6 +212,14 @@ $db-bar-height: var(--space-2);
border-radius: var(--d-border-radius);
}
+.db-main__error {
+ padding: var(--space-8);
+ text-align: center;
+ color: var(--primary-medium);
+ background: var(--primary-very-low);
+ border-radius: var(--d-border-radius);
+}
+
.db-link-arrow {
position: absolute;
opacity: 0;
@@ -253,6 +261,17 @@ $db-bar-height: var(--space-2);
margin: 0;
}
+ &__error {
+ grid-column: 1 / -1;
+ flex: 1;
+ padding: var(--space-8);
+ text-align: center;
+ color: var(--primary-medium);
+ background: var(--primary-very-low);
+ border-radius: var(--d-border-radius);
+ font-size: var(--font-down-1-rem);
+ }
+
&__subheader {
display: flex;
justify-content: space-between;
diff --git a/app/services/admin_dashboard_section_loader.rb b/app/services/admin_dashboard_section_loader.rb
index cf58a4faf95..f2c68bb0f82 100644
--- a/app/services/admin_dashboard_section_loader.rb
+++ b/app/services/admin_dashboard_section_loader.rb
@@ -48,7 +48,17 @@ class AdminDashboardSectionLoader
section_ids.size.times do
result = results.pop
- raise result[:error] if result[:error]
+
+ if result[:error]
+ Discourse.warn_exception(
+ result[:error],
+ message: "Failed to build admin dashboard section",
+ env: {
+ section_id: result[:id],
+ },
+ )
+ result = { id: result[:id], data: nil, error: true }
+ end
results_by_id[result[:id]] = result
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c98682c4e96..cef7acb1ad5 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7168,6 +7168,7 @@ en:
not_found_error: Sorry, this report doesn’t exist
custom_date_range: Custom date range
loading: "Loading dashboard…"
+ fetch_error: "Couldn't load the dashboard. Try refreshing the page."
stable: "stable"
sections:
@@ -7175,6 +7176,7 @@ en:
title: "Highlights"
reports:
title: "Reports"
+ fetch_error: "Couldn't load reports. Try refreshing the page."
traffic:
title: "Site traffic"
engagement:
diff --git a/frontend/discourse/admin/components/dashboard/highlights.gjs b/frontend/discourse/admin/components/dashboard/highlights.gjs
index fa8ebb686fd..9f11a344550 100644
--- a/frontend/discourse/admin/components/dashboard/highlights.gjs
+++ b/frontend/discourse/admin/components/dashboard/highlights.gjs
@@ -40,7 +40,7 @@ export default class Highlights extends Component {
</:intro>
<:default>
{{#if @fetchError}}
- <div class="db-highlights__error" role="alert">
+ <div class="db-section__error" role="alert">
{{i18n "admin.dashboard.highlights.fetch_error"}}
</div>
{{else}}
diff --git a/frontend/discourse/admin/components/dashboard/reports.gjs b/frontend/discourse/admin/components/dashboard/reports.gjs
index 9d4d339fc78..2dc378d11b1 100644
--- a/frontend/discourse/admin/components/dashboard/reports.gjs
+++ b/frontend/discourse/admin/components/dashboard/reports.gjs
@@ -133,59 +133,68 @@ export default class DashboardReports extends Component {
@endDate={{@endDate}}
...attributes
>
- <div
- class="db-reports"
- {{didUpdate this.loadPayloads @data @startDate @endDate}}
- >
- {{#each this.cards key="key" as |card|}}
- <div class="db-report__card" data-identifier={{card.key}}>
- <div class="db-report__header">
- <a href={{card.url}} class="db-report__name">{{card.title}}</a>
- {{#if card.label}}
- <div
- class={{dConcatClass
- "db-report__label"
- (concat "--" card.source)
- }}
- data-source={{card.source}}
- >{{card.label}}</div>
- {{/if}}
- </div>
- <div class="db-report__chart">
- {{#if card.payload}}
- {{#if card.payload.empty}}
- <DashboardReportEmptyState />
- {{else}}
- {{#let
- (lookupAdminDashboardReportRenderer card.source)
- as |Renderer|
- }}
- {{#if Renderer}}
- <Renderer
- @item={{card}}
- @payload={{card.payload}}
- @filters={{hash startDate=@startDate endDate=@endDate}}
- />
- {{/if}}
- {{/let}}
+ {{#if @fetchError}}
+ <div class="db-section__error" role="alert">
+ {{i18n "admin.dashboard.sections.reports.fetch_error"}}
+ </div>
+ {{else}}
+ <div
+ class="db-reports"
+ {{didUpdate this.loadPayloads @data @startDate @endDate}}
+ >
+ {{#each this.cards key="key" as |card|}}
+ <div class="db-report__card" data-identifier={{card.key}}>
+ <div class="db-report__header">
+ <a href={{card.url}} class="db-report__name">{{card.title}}</a>
+ {{#if card.label}}
+ <div
+ class={{dConcatClass
+ "db-report__label"
+ (concat "--" card.source)
+ }}
+ data-source={{card.source}}
+ >{{card.label}}</div>
+ {{/if}}
+ </div>
+ <div class="db-report__chart">
+ {{#if card.payload}}
+ {{#if card.payload.empty}}
+ <DashboardReportEmptyState />
+ {{else}}
+ {{#let
+ (lookupAdminDashboardReportRenderer card.source)
+ as |Renderer|
+ }}
+ {{#if Renderer}}
+ <Renderer
+ @item={{card}}
+ @payload={{card.payload}}
+ @filters={{hash
+ startDate=@startDate
+ endDate=@endDate
+ }}
+ />
+ {{/if}}
+ {{/let}}
+ {{/if}}
{{/if}}
- {{/if}}
+ </div>
</div>
- </div>
- {{/each}}
-
- {{#if this.addTileVisible}}
- <button
- type="button"
- class="db-report__add-report"
- aria-label={{i18n "admin.dashboard.reports_section.add"}}
- {{on "click" this.openReportsConfig}}
- >
- <span>{{dIcon "plus"}}
- {{i18n "admin.dashboard.reports_section.add"}}</span>
- </button>
- {{/if}}
- </div>
+ {{/each}}
+
+ {{#if this.addTileVisible}}
+ <button
+ type="button"
+ class="db-report__add-report"
+ aria-label={{i18n "admin.dashboard.reports_section.add"}}
+ {{on "click" this.openReportsConfig}}
+ >
+ <span>{{dIcon "plus"}}
+ {{i18n "admin.dashboard.reports_section.add"}}</span>
+ </button>
+ {{/if}}
+ </div>
+ {{/if}}
<PluginOutlet
@name="admin-dashboard-reports-section-after"
diff --git a/frontend/discourse/admin/components/redesigned-admin-dashboard.gjs b/frontend/discourse/admin/components/redesigned-admin-dashboard.gjs
index f126ed82c3a..c43147fd7d7 100644
--- a/frontend/discourse/admin/components/redesigned-admin-dashboard.gjs
+++ b/frontend/discourse/admin/components/redesigned-admin-dashboard.gjs
@@ -78,7 +78,11 @@ export default class RedesignedAdminDashboard extends Component {
/>
<div class="db-main">
- {{#if @loadedSections}}
+ {{#if @sectionsFetchError}}
+ <div class="db-main__error" role="alert">
+ {{i18n "admin.dashboard.fetch_error"}}
+ </div>
+ {{else if @loadedSections}}
<DashboardSiteAdvice
@problems={{@problems}}
@onRefresh={{@onRefreshProblems}}
@@ -93,7 +97,7 @@ export default class RedesignedAdminDashboard extends Component {
@highlights={{section.data}}
@period={{@loadedSections.period}}
@loading={{@loadingSections}}
- @fetchError={{@sectionsFetchError}}
+ @fetchError={{section.error}}
@startDate={{@loadedSections.startDate}}
@endDate={{@loadedSections.endDate}}
/>
@@ -105,6 +109,7 @@ export default class RedesignedAdminDashboard extends Component {
@startDate={{@loadedSections.startDate}}
@endDate={{@loadedSections.endDate}}
@refreshSections={{@refreshSections}}
+ @fetchError={{section.error}}
/>
{{else if (eq section.id "traffic")}}
<DashboardTraffic
@@ -113,7 +118,7 @@ export default class RedesignedAdminDashboard extends Component {
@traffic={{section.data}}
@period={{@loadedSections.period}}
@loading={{@loadingSections}}
- @fetchError={{@sectionsFetchError}}
+ @fetchError={{section.error}}
@startDate={{@loadedSections.startDate}}
@endDate={{@loadedSections.endDate}}
/>
@@ -124,7 +129,7 @@ export default class RedesignedAdminDashboard extends Component {
@engagement={{section.data}}
@period={{@loadedSections.period}}
@loading={{@loadingSections}}
- @fetchError={{@sectionsFetchError}}
+ @fetchError={{section.error}}
@startDate={{@loadedSections.startDate}}
@endDate={{@loadedSections.endDate}}
/>
@@ -135,7 +140,7 @@ export default class RedesignedAdminDashboard extends Component {
@search={{section.data}}
@period={{@loadedSections.period}}
@loading={{@loadingSections}}
- @fetchError={{@sectionsFetchError}}
+ @fetchError={{section.error}}
@startDate={{@loadedSections.startDate}}
@endDate={{@loadedSections.endDate}}
/>
@@ -148,7 +153,7 @@ export default class RedesignedAdminDashboard extends Component {
@data={{section.data}}
@period={{@loadedSections.period}}
@loading={{@loadingSections}}
- @fetchError={{@sectionsFetchError}}
+ @fetchError={{section.error}}
@startDate={{@loadedSections.startDate}}
@endDate={{@loadedSections.endDate}}
/>
diff --git a/frontend/discourse/tests/integration/components/dashboard/highlights-test.gjs b/frontend/discourse/tests/integration/components/dashboard/highlights-test.gjs
index 016c22c8ea4..ce6eac3d3ea 100644
--- a/frontend/discourse/tests/integration/components/dashboard/highlights-test.gjs
+++ b/frontend/discourse/tests/integration/components/dashboard/highlights-test.gjs
@@ -139,7 +139,7 @@ module("Integration | Component | Dashboard | Highlights", function (hooks) {
</template>
);
- assert.dom(".db-highlights__error").exists();
+ assert.dom(".db-section__error").exists();
assert.dom(".db-kpi").doesNotExist();
});
});
diff --git a/frontend/discourse/tests/integration/components/dashboard/reports-test.gjs b/frontend/discourse/tests/integration/components/dashboard/reports-test.gjs
new file mode 100644
index 00000000000..862d70bfe22
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/dashboard/reports-test.gjs
@@ -0,0 +1,28 @@
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import DashboardReports from "discourse/admin/components/dashboard/reports";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import { i18n } from "discourse-i18n";
+
+module("Integration | Component | DashboardReports", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("displays an error when the section failed to load", async function (assert) {
+ await render(
+ <template>
+ <DashboardReports @data={{null}} @fetchError={{true}} />
+ </template>
+ );
+
+ assert
+ .dom(".db-section__error")
+ .hasText(
+ i18n("admin.dashboard.sections.reports.fetch_error"),
+ "the fetch error is shown"
+ );
+ assert.dom(".db-reports").doesNotExist("the reports grid is not rendered");
+ assert
+ .dom(".db-report__add-report")
+ .doesNotExist("the add report button is not rendered");
+ });
+});
diff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rb
index 4b603176d85..d2adfb4e20f 100644
--- a/spec/requests/admin/dashboard_controller_spec.rb
+++ b/spec/requests/admin/dashboard_controller_spec.rb
@@ -412,6 +412,39 @@ RSpec.describe Admin::DashboardController do
expect(ids).to eq(%w[reports highlights])
end
+ it "returns successful sections when another section fails to build" do
+ error = StandardError.new("boom")
+ configure_dashboard_sections(%w[highlights search])
+ AdminDashboardHighlights.stubs(:build).returns({ value: "highlights" })
+ AdminDashboardSearch.stubs(:build).raises(error)
+ Discourse.expects(:warn_exception).with(
+ error,
+ message: "Failed to build admin dashboard section",
+ env: {
+ section_id: "search",
+ },
+ )
+
+ get "/admin/dashboard.json"
+
+ expect(response.status).to eq(200)
+ expect(section_payloads).to eq(
+ "highlights" => {
+ "id" => "highlights",
+ "data" => {
+ "value" => "highlights",
+ },
+ },
+ "search" => {
+ "id" => "search",
+ "data" => nil,
+ "error" => true,
+ },
+ )
+ expect(response.parsed_body["configuration"]).to be_present
+ expect(response.parsed_body).to have_key("problems")
+ end
+
it "omits hidden sections from the data payload" do
configure_dashboard_sections(%w[highlights reports])
diff --git a/spec/services/admin_dashboard_section_loader_spec.rb b/spec/services/admin_dashboard_section_loader_spec.rb
index 7b11811bfe4..ca5012d868e 100644
--- a/spec/services/admin_dashboard_section_loader_spec.rb
+++ b/spec/services/admin_dashboard_section_loader_spec.rb
@@ -44,6 +44,30 @@ describe AdminDashboardSectionLoader do
],
)
end
+
+ it "returns partial section data when a section fails to build" do
+ error = StandardError.new("boom")
+ AdminDashboardSiteTraffic.stubs(:build).returns({ value: "traffic" })
+ AdminDashboardSearch.stubs(:build).raises(error)
+ Discourse.expects(:warn_exception).with(
+ error,
+ message: "Failed to build admin dashboard section",
+ env: {
+ section_id: "search",
+ },
+ )
+
+ expect(
+ described_class.build(
+ section_ids: %w[traffic search],
+ current_user: admin,
+ start_date: "2026-05-01",
+ end_date: "2026-05-07",
+ ),
+ ).to eq(
+ [{ id: "traffic", data: { value: "traffic" } }, { id: "search", data: nil, error: true }],
+ )
+ end
end
describe "plugin sections" do