From 7a9128ac36457f6a7bffe14ab39154715eb045a6 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 14 Dec 2022 13:51:04 +0100 Subject: [PATCH] [v9.3.x] Dashboards: Show error when data source is missing (#60313) Dashboards: Show error when data source is missing (#60099) Return caught exceptions to panel as error state (cherry picked from commit 9a41277ecdbf327fadb6acfbf0e3415098d6503c) Co-authored-by: Josh Hunt --- .../grafana-runtime/src/utils/toDataQueryError.ts | 2 +- public/app/features/query/state/PanelQueryRunner.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/grafana-runtime/src/utils/toDataQueryError.ts b/packages/grafana-runtime/src/utils/toDataQueryError.ts index 457709d514d0..28946be81090 100644 --- a/packages/grafana-runtime/src/utils/toDataQueryError.ts +++ b/packages/grafana-runtime/src/utils/toDataQueryError.ts @@ -6,7 +6,7 @@ import { DataQueryError } from '@grafana/data'; * * @public */ -export function toDataQueryError(err: DataQueryError | string | Object): DataQueryError { +export function toDataQueryError(err: DataQueryError | string | unknown): DataQueryError { const error = (err || {}) as DataQueryError; if (!error.message) { diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index 3f3a2c480b87..6bd24a19e5ff 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -25,7 +25,7 @@ import { toDataFrame, transformDataFrame, } from '@grafana/data'; -import { getTemplateSrv } from '@grafana/runtime'; +import { getTemplateSrv, toDataQueryError } from '@grafana/runtime'; import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend'; import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame'; import { isStreamingDataFrame } from 'app/features/live/data/utils'; @@ -274,7 +274,15 @@ export class PanelQueryRunner { this.pipeToSubject(runRequest(ds, request), panelId); } catch (err) { - console.error('PanelQueryRunner Error', err); + this.pipeToSubject( + of({ + state: LoadingState.Error, + error: toDataQueryError(err), + series: [], + timeRange: request.range, + }), + panelId + ); } }