فهرست منبع

feat(plugins): added better error message when trying to load data source plugin module that is missing datasource constructor

Torkel Ödegaard 10 سال پیش
والد
کامیت
15546dd84e
2فایلهای تغییر یافته به همراه7 افزوده شده و 4 حذف شده
  1. 4 0
      public/app/core/services/alert_srv.js
  2. 3 4
      public/app/core/services/datasource_srv.js

+ 4 - 0
public/app/core/services/alert_srv.js

@@ -46,6 +46,10 @@ function (angular, _, coreModule) {
         }, timeout);
       }
 
+      if (!$rootScope.$$phase) {
+        $rootScope.$digest();
+      }
+
       return(newAlert);
     };
 

+ 3 - 4
public/app/core/services/datasource_srv.js

@@ -7,7 +7,7 @@ define([
 function (angular, _, coreModule, config) {
   'use strict';
 
-  coreModule.default.service('datasourceSrv', function($q, $injector) {
+  coreModule.default.service('datasourceSrv', function($q, $injector, $rootScope) {
     var self = this;
 
     this.init = function() {
@@ -60,7 +60,6 @@ function (angular, _, coreModule, config) {
       var deferred = $q.defer();
       var pluginDef = dsConfig.meta;
 
-      console.log(pluginDef);
       System.import(pluginDef.module).then(function(plugin) {
         // check if its in cache now
         if (self.datasources[name]) {
@@ -70,7 +69,7 @@ function (angular, _, coreModule, config) {
 
         // plugin module needs to export a constructor function named Datasource
         if (!plugin.Datasource) {
-          return;
+          throw "Plugin module is missing Datasource constructor";
         }
 
         var instance = $injector.instantiate(plugin.Datasource, {instanceSettings: dsConfig});
@@ -79,7 +78,7 @@ function (angular, _, coreModule, config) {
         self.datasources[name] = instance;
         deferred.resolve(instance);
       }).catch(function(err) {
-        console.log('Failed to load data source: ' + err);
+        $rootScope.appEvent('alert-error', [dsConfig.name + ' plugin failed', err.toString()]);
       });
 
       return deferred.promise;