Skip to content
Snippets Groups Projects
Commit 6556859d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when plugin crash on upload it's removed from the system properly

parent b9e9d3c9
No related branches found
No related tags found
1 merge request!877Resolve "MINERVANET - Error Report 93"
Pipeline #12731 passed
......@@ -8,6 +8,8 @@ minerva (14.0.0~alpha.1) unstable; urgency=low
* Bug fix: some project couldn't be accessed due to problem with migration of
reaction with unknown boolean operator (#880)
* Bug fix: problem with unloading plugin is properly handled (#884)
* Bug fix: upload of invalid plugin doesn't add it to plugin tab and list of
loaded plugins (#885)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 12 Aug 2019 10:00:00 +0200
......
......@@ -107,6 +107,10 @@ Plugin.prototype.getMinervaPluginProxy = function () {
* @returns {string}
*/
Plugin.prototype.getPluginId = function () {
if (this.getMinervaPluginProxy() === undefined) {
logger.warn("Plugin is not loaded properly");
return undefined;
}
return this.getMinervaPluginProxy().pluginId;
};
......
......@@ -94,6 +94,7 @@ PluginManager.prototype.addPlugin = function (options) {
map: self.getMap(),
serverConnector: self.getServerConnector()
});
self._plugins.push(plugin);
} else {
plugin = new Plugin({
url: options.url,
......@@ -105,11 +106,11 @@ PluginManager.prototype.addPlugin = function (options) {
plugin.addListener("onUnload", function () {
self.getGuiUtils().removeTab(self, element);
});
self._plugins.push(plugin);
if (!self.isValidUrl(options.url)) {
return Promise.reject(new InvalidArgumentError("url: '" + options.url + "' is invalid"));
}
}
self._plugins.push(plugin);
return plugin.load();
}).then(function () {
$("a[href='#" + element.parentNode.id + "']", $(self.getElement()))[0].innerHTML = plugin.getName();
......@@ -140,7 +141,7 @@ PluginManager.prototype.addPlugin = function (options) {
GuiConnector.setUrlParam("plugins", self._getLoadedPluginsAsHashList());
return plugin;
}).catch(function (e) {
return plugin.unload().then(function () {
return self.removePlugin(plugin).then(function () {
GuiConnector.alert("Problem with loading plugin:<br/>" + e.message);
});
});
......
......@@ -88,10 +88,11 @@ describe('PluginManager', function () {
it('with error', function () {
var manager = createPluginManager();
return manager.addPlugin({url: "./invalid.js"}).then(function (plugin) {
return manager.addPlugin({url: "./invalid.js"}).then(function () {
assert.notOk("Expected error");
}).catch(function (e) {
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0)
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0);
assert.equal(0, manager.getPlugins().length);
});
});
it('with invalid url', function () {
......@@ -99,7 +100,7 @@ describe('PluginManager', function () {
manager.isValidUrl = function () {
return false;
};
return manager.addPlugin({url: "xx"}).then(function (plugin) {
return manager.addPlugin({url: "xx"}).then(function () {
assert.notOk("Expected error");
}).catch(function (e) {
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0)
......@@ -146,7 +147,14 @@ describe('PluginManager', function () {
it('removing non existing plugin', function () {
var manager = createPluginManager();
var plugin = new Plugin({url: "testFiles/plugin/empty.js"});
var plugin = new Plugin({
url: "testFiles/plugin/empty.js",
map: manager.getMap(),
configuration: manager.getConfiguration(),
serverConnector: manager.getServerConnector(),
element: testDiv
});
return manager.removePlugin(plugin).then(function () {
assert.notOk("Error expected");
}, function (error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment