From e3ce69ef22aa06f0897f71fcef9fad8b94c051d5 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Wed, 14 Dec 2022 12:37:31 +0000 Subject: [PATCH] Dashboards: Show error when data source is missing (#60099) Return caught exceptions to panel as error state (cherry picked from commit 9a41277ecdbf327fadb6acfbf0e3415098d6503c) --- .../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 + ); } }