Skip to content

Commit 2f41969

Browse files
kibanamachinenreeseelasticmachine
authored
[8.19] [dashboard] fix invalid dashboard displayed as 404 instead of showing validation error (#211661) (#220427)
# Backport This will backport the following commits from `main` to `8.19`: - [[dashboard] fix invalid dashboard displayed as 404 instead of showing validation error (#211661)](#211661) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Nathan Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-05-07T19:32:04Z","message":"[dashboard] fix invalid dashboard displayed as 404 instead of showing validation error (#211661)\n\nCloses https://github.com/elastic/kibana/issues/211659\n\nPR updates `loadDashboardState` to throw content management error when\nstatus is not a 404. PR does not attempt to clean-up DashboardRenderer's\ndisplay of the error.\n\n<img width=\"500\" alt=\"Screenshot 2025-05-07 at 8 20 02 AM\"\nsrc=\"https://github.com/user-attachments/assets/39883951-d4df-46fa-9950-bb8103898b6b\"\n/>\n\n\n### test instructions\n1) use saved object import to import dashboard with schema errors -\nhttps://github.com/elastic/kibana/blob/main/x-pack/test/functional/apps/dashboard/group2/migration_smoke_tests/exports/lens_dashboard_migration_test_7_12_1.ndjson.\n2) open dashboard, verify schema validation error is displayed.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>\nCo-authored-by: Elastic Machine <[email protected]>","sha":"670ff4ee06089711a20201c0093c83abbe4db2bf","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","backport:version","v9.1.0","v8.19.0"],"title":"[dashboard] fix invalid dashboard displayed as 404 instead of showing validation error","number":211661,"url":"https://github.com/elastic/kibana/pull/211661","mergeCommit":{"message":"[dashboard] fix invalid dashboard displayed as 404 instead of showing validation error (#211661)\n\nCloses https://github.com/elastic/kibana/issues/211659\n\nPR updates `loadDashboardState` to throw content management error when\nstatus is not a 404. PR does not attempt to clean-up DashboardRenderer's\ndisplay of the error.\n\n<img width=\"500\" alt=\"Screenshot 2025-05-07 at 8 20 02 AM\"\nsrc=\"https://github.com/user-attachments/assets/39883951-d4df-46fa-9950-bb8103898b6b\"\n/>\n\n\n### test instructions\n1) use saved object import to import dashboard with schema errors -\nhttps://github.com/elastic/kibana/blob/main/x-pack/test/functional/apps/dashboard/group2/migration_smoke_tests/exports/lens_dashboard_migration_test_7_12_1.ndjson.\n2) open dashboard, verify schema validation error is displayed.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>\nCo-authored-by: Elastic Machine <[email protected]>","sha":"670ff4ee06089711a20201c0093c83abbe4db2bf"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211661","number":211661,"mergeCommit":{"message":"[dashboard] fix invalid dashboard displayed as 404 instead of showing validation error (#211661)\n\nCloses https://github.com/elastic/kibana/issues/211659\n\nPR updates `loadDashboardState` to throw content management error when\nstatus is not a 404. PR does not attempt to clean-up DashboardRenderer's\ndisplay of the error.\n\n<img width=\"500\" alt=\"Screenshot 2025-05-07 at 8 20 02 AM\"\nsrc=\"https://github.com/user-attachments/assets/39883951-d4df-46fa-9950-bb8103898b6b\"\n/>\n\n\n### test instructions\n1) use saved object import to import dashboard with schema errors -\nhttps://github.com/elastic/kibana/blob/main/x-pack/test/functional/apps/dashboard/group2/migration_smoke_tests/exports/lens_dashboard_migration_test_7_12_1.ndjson.\n2) open dashboard, verify schema validation error is displayed.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>\nCo-authored-by: Elastic Machine <[email protected]>","sha":"670ff4ee06089711a20201c0093c83abbe4db2bf"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Nathan Reese <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 93410b2 commit 2f41969

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/platform/plugins/shared/dashboard/public/dashboard_renderer/dashboard_renderer.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import './_dashboard_container.scss';
1212
import classNames from 'classnames';
1313
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
1414

15-
import { EuiLoadingElastic, EuiLoadingSpinner } from '@elastic/eui';
15+
import { EuiEmptyPrompt, EuiLoadingElastic, EuiLoadingSpinner } from '@elastic/eui';
1616
import { SavedObjectNotFound } from '@kbn/kibana-utils-plugin/common';
1717
import { useStateFromPublishingSubject } from '@kbn/presentation-publishing';
1818
import { LocatorPublic } from '@kbn/share-plugin/common';
1919

2020
import { ExitFullScreenButtonKibanaProvider } from '@kbn/shared-ux-button-exit-full-screen';
21+
import { i18n } from '@kbn/i18n';
2122
import type { DashboardLocatorParams } from '../../common';
2223
import { DashboardApi, DashboardInternalApi } from '../dashboard_api/types';
2324
import { coreServices, screenshotModeService } from '../services/kibana_services';
@@ -108,7 +109,18 @@ export function DashboardRenderer({
108109
return error instanceof SavedObjectNotFound ? (
109110
<Dashboard404Page dashboardRedirect={dashboardRedirect} />
110111
) : (
111-
error.message
112+
<EuiEmptyPrompt
113+
iconType="error"
114+
iconColor="danger"
115+
title={
116+
<h2>
117+
{i18n.translate('dashboard.dashboardRenderer.loadDashboardErrorTitle', {
118+
defaultMessage: 'Unable to load dashboard',
119+
})}
120+
</h2>
121+
}
122+
body={<p>{error.message}</p>}
123+
/>
112124
);
113125
}
114126

src/platform/plugins/shared/dashboard/public/services/dashboard_content_management_service/lib/load_dashboard_state.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import { has } from 'lodash';
11-
1211
import { injectSearchSourceReferences } from '@kbn/data-plugin/public';
1312
import { Filter, Query } from '@kbn/es-query';
1413
import { SavedObjectNotFound } from '@kbn/kibana-utils-plugin/public';
@@ -85,7 +84,11 @@ export const loadDashboardState = async ({
8584
id,
8685
})
8786
.catch((e) => {
88-
throw new SavedObjectNotFound(DASHBOARD_CONTENT_ID, id);
87+
if (e.response?.status === 404) {
88+
throw new SavedObjectNotFound(DASHBOARD_CONTENT_ID, id);
89+
}
90+
const message = (e.body as { message?: string })?.message ?? e.message;
91+
throw new Error(message);
8992
});
9093

9194
({ item: rawDashboardContent, meta: resolveMeta } = result);
@@ -136,7 +139,7 @@ export const loadDashboardState = async ({
136139
references
137140
) as DashboardSearchSource;
138141
return await dataSearchService.searchSource.create(searchSourceValues);
139-
} catch (error: any) {
142+
} catch (error) {
140143
return await dataSearchService.searchSource.create();
141144
}
142145
})();

0 commit comments

Comments
 (0)