Commit 744b5a6f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when plugin listener crash system notifies user and plugin about a problem

parent 90c77341
......@@ -31,6 +31,8 @@ minerva (12.3.0~alpha.0) unstable; urgency=low
(#591)
* Small improvement: uploading sbml file should automatically discover a file
type (#784)
* Small improvement: when plugin listeners crash the system notifies user
about problem with a plugin (#767)
* Bug fix: progress bar of gene genome mapping upload is refreshing properly
(#728)
* Bug fix: when editing project Disease and Organism could not be removed
......
......@@ -12,6 +12,8 @@ var Configuration = require('../Configuration');
var Bounds = require('../map/canvas/Bounds');
var Point = require('../map/canvas/Point');
var GuiConnector = require('../GuiConnector');
// noinspection JSUnusedLocalSymbols
var logger = require('../logger');
......@@ -453,7 +455,7 @@ function createProjectMap(options) {
return dbOverlay.searchByQuery(params.query, params.perfect, params.fitBounds);
} else if (dbOverlay instanceof SearchDbOverlay) {
var zoom = params.zoom;
if (zoom ===undefined) {
if (zoom === undefined) {
zoom = map.getSubmapById(params.modelId).getZoom();
}
return dbOverlay.searchByCoordinates({
......@@ -582,10 +584,26 @@ function createProjectMap(options) {
throw new Error("Invalid argument");
}
var wrapper = function (e) {
try {
return Promise.resolve(listenerWrapper(e)).catch(function (error) {
GuiConnector.warn("Plugin " + options.plugin.getName() + " crashed");
if (typeof options.plugin.getLoadedPluginData().notifyError === "function") {
options.plugin.getLoadedPluginData().notifyError({listener: param, data: e, error: error});
}
});
} catch (error) {
GuiConnector.warn("Plugin " + options.plugin.getName() + " crashed");
if (typeof options.plugin.getLoadedPluginData().notifyError === "function") {
options.plugin.getLoadedPluginData().notifyError({listener: param, data: e, error: error});
}
}
};
for (var i = 0; i < objects.length; i++) {
var object = objects[i];
object.addListener(listenerType, listenerWrapper);
listenersData.push({listener: param.callback, wrapper: listenerWrapper, object: object, type: listenerType});
object.addListener(listenerType, wrapper);
listenersData.push({listener: param.callback, wrapper: wrapper, object: object, type: listenerType});
}
},
/**
......
......@@ -24,6 +24,7 @@ var pluginId = 0;
* @typedef {Object} UserPluginObject
* @property {function(Object):void} register
* @property {function():void} unregister
* @property {function(Object):void} [notifyError]
* @property {function():string} getName
* @property {function():string} getVersion
* @property {function():(number|string)|number|string} minWidth
......
......@@ -5,6 +5,7 @@ require("../mocha-config");
// noinspection JSUnusedLocalSymbols
var Promise = require("bluebird");
var Plugin = require('../../../main/js/plugin/Plugin');
var Point = require('../../../main/js/map/canvas/Point');
var ServerConnector = require('../ServerConnector-mock');
var logger = require('../logger');
......@@ -106,4 +107,14 @@ describe('Plugin', function () {
});
});
});
it('plugin listener crash', function () {
var map = helper.createCustomMap();
var plugin = createPlugin("./testFiles/plugin/listener-crash.js", map);
return plugin.load().then(function () {
return map.callListeners("onCenterChanged", new Point(0, 0));
}).then(function () {
assert.equal(1, logger.getWarnings().length);
});
});
});
{
"hash": "d5d652ac0e0f6467d4cb6a742f99d3f7",
"name": "test plugin",
"urls": [
"./testFiles/plugin-invalid/invalid_register.js"
],
"version": "0.0.1"
}
\ No newline at end of file
minervaDefine(function () {
return {
register: function (minervaObject) {
var options = {
object: "map",
type: "onCenterChanged",
callback: function () {
throw new Error("Let's crash");
}
};
minervaObject.project.map.addListener(options);
},
unregister: function () {
console.log("unregistering test plugin");
},
getName: function () {
return "test plugin";
},
getVersion: function () {
return "0.0.1";
}
};
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment