Commit e157e67c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

handle crash on plugin unload

parent 254dc97c
......@@ -7,6 +7,7 @@ var Promise = require("bluebird");
var logger = require('../logger');
var Functions = require('../Functions');
var GuiConnector = require('../GuiConnector');
var PluginData = require('../map/data/PluginData');
var pluginId = 0;
......@@ -226,6 +227,11 @@ Plugin.prototype.unload = function () {
if (validPlugin) {
return self.getLoadedPluginData().unregister();
}
}).catch(function (e) {
GuiConnector.warn("Plugin crashed on upload.");
if (typeof self.getLoadedPluginData().notifyError === "function") {
self.getLoadedPluginData().notifyError({error: error});
}
}).then(function () {
if (validPlugin) {
var removedListeners = self.getMinervaPluginProxy().project.map.removeAllListeners();
......
......@@ -110,6 +110,18 @@ describe('Plugin', function () {
assert.equal(1, logger.getWarnings().length);
});
});
it('plugin crashed during unload', function () {
var map = helper.createCustomMap();
helper.createSearchDbOverlay(map);
var plugin = createPlugin("./testFiles/plugin-invalid/crash-unregister.js", map);
return plugin.load().then(function () {
assert.equal(0, logger.getWarnings().length);
return plugin.unload();
}).then(function () {
assert.equal(2, logger.getWarnings().length);
});
});
});
it('plugin listener crash', function () {
var map = helper.createCustomMap();
......
{
"hash": "dac1c83fdedde144a3c09424f88c9804",
"name": "test plugin",
"urls": [
"./testFiles/plugin-invalid/crash-unregister.js"
],
"version": "0.0.1"
}
\ No newline at end of file
minervaDefine(function () {
return {
register: function (minervaObject) {
var options = {
dbOverlayName: "search",
type: "onSearch",
callback: function (elements) {
console.log("hi there");
}
};
minervaObject.project.map.addListener(options);
},
unregister: function () {
throw new Error("ups")
},
getName: function () {
return "high test";
},
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