瀏覽代碼

Catch bad regex exception at controller level

SamuelToh 6 年之前
父節點
當前提交
d2c161c2e6
共有 2 個文件被更改,包括 7 次插入8 次删除
  1. 2 7
      public/app/core/time_series2.ts
  2. 5 1
      public/app/plugins/panel/graph/module.ts

+ 2 - 7
public/app/core/time_series2.ts

@@ -1,5 +1,4 @@
 import kbn from 'app/core/utils/kbn';
 import kbn from 'app/core/utils/kbn';
-import { appEvents } from 'app/core/core';
 import { getFlotTickDecimals } from 'app/core/utils/ticks';
 import { getFlotTickDecimals } from 'app/core/utils/ticks';
 import _ from 'lodash';
 import _ from 'lodash';
 import { getValueFormat } from '@grafana/ui';
 import { getValueFormat } from '@grafana/ui';
@@ -10,12 +9,8 @@ function matchSeriesOverride(aliasOrRegex, seriesAlias) {
   }
   }
 
 
   if (aliasOrRegex[0] === '/') {
   if (aliasOrRegex[0] === '/') {
-    try {
-      const regex = kbn.stringToJsRegex(aliasOrRegex);
-      return seriesAlias.match(regex) != null;
-    } catch (e) {
-      return appEvents.emit('alert-error', ['Invalid aliasOrRegex value.', e.message]);
-    }
+    const regex = kbn.stringToJsRegex(aliasOrRegex);
+    return seriesAlias.match(regex) != null;
   }
   }
 
 
   return aliasOrRegex === seriesAlias;
   return aliasOrRegex === seriesAlias;

+ 5 - 1
public/app/plugins/panel/graph/module.ts

@@ -235,7 +235,11 @@ class GraphCtrl extends MetricsPanelCtrl {
     }
     }
 
 
     for (const series of this.seriesList) {
     for (const series of this.seriesList) {
-      series.applySeriesOverrides(this.panel.seriesOverrides);
+      try {
+        series.applySeriesOverrides(this.panel.seriesOverrides);
+      } catch (e) {
+        this.publishAppEvent('alert-error', [e.message]);
+      }
 
 
       if (series.unit) {
       if (series.unit) {
         this.panel.yaxes[series.yaxis - 1].format = series.unit;
         this.panel.yaxes[series.yaxis - 1].format = series.unit;