From 9a41277ecdbf327fadb6acfbf0e3415098d6503c 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 --- .../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 457709d514d..28946be8109 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 9509d089e13..0aaeb6f7add 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'; @@ -276,7 +276,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 + ); } }