From 0266d7cc365641081d4e69ec353c3298d469a32c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 15 Mar 2018 14:17:18 +0100 Subject: [PATCH] error handling in plugin loa improved (when plugins crash) --- frontend-js/src/main/js/plugin/Plugin.js | 6 ++++++ frontend-js/src/test/js/plugin/Plugin-test.js | 8 ++++---- ...lt-promise-crash.js&version=0.0.1&token=MOCK_TOKEN_ID& | 8 ++++++++ ...n-invalid%2Finvalid_javascript.js&token=MOCK_TOKEN_ID& | 8 ++++++++ ...invalid_register.js&version=0.0.1&token=MOCK_TOKEN_ID& | 8 ++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 frontend-js/testFiles/apiCalls/plugins/POST_hash=273dffdc94ef22531b90fb4489ba00c3&name=plugin%20with%20promise&url=.%2FtestFiles%2Fplugin-invalid%2Fresult-promise-crash.js&version=0.0.1&token=MOCK_TOKEN_ID& create mode 100644 frontend-js/testFiles/apiCalls/plugins/POST_hash=c36d817fb1e6c3a7b569ee9ba55baa76&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_javascript.js&token=MOCK_TOKEN_ID& create mode 100644 frontend-js/testFiles/apiCalls/plugins/POST_hash=d5d652ac0e0f6467d4cb6a742f99d3f7&name=test%20plugin&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_register.js&version=0.0.1&token=MOCK_TOKEN_ID& diff --git a/frontend-js/src/main/js/plugin/Plugin.js b/frontend-js/src/main/js/plugin/Plugin.js index f8ee085afc..f97b46111d 100644 --- a/frontend-js/src/main/js/plugin/Plugin.js +++ b/frontend-js/src/main/js/plugin/Plugin.js @@ -135,10 +135,16 @@ Plugin.prototype.unload = function () { }; Plugin.prototype.getName = function () { + if (this.getLoadedPluginData() === undefined) { + return ""; + } return this.getLoadedPluginData().getName(); }; Plugin.prototype.getVersion = function () { + if (this.getLoadedPluginData() === undefined) { + return ""; + } return this.getLoadedPluginData().getVersion(); }; diff --git a/frontend-js/src/test/js/plugin/Plugin-test.js b/frontend-js/src/test/js/plugin/Plugin-test.js index 13a83633b1..e2bcfd6091 100644 --- a/frontend-js/src/test/js/plugin/Plugin-test.js +++ b/frontend-js/src/test/js/plugin/Plugin-test.js @@ -62,7 +62,7 @@ describe('Plugin', function () { return plugin.load().then(function () { assert.notOk("expected error"); }, function (error) { - assert.ok(error.message.indexOf("Unexpected identifier") >= 0); + assert.ok(error.message.indexOf("Unexpected identifier") >= 0, "Wrong message: " + error.message); }); }); @@ -75,7 +75,7 @@ describe('Plugin', function () { return plugin.load().then(function () { assert.false("expected error"); }, function (error) { - assert.ok(error.message.indexOf("Let's crash") >= 0); + assert.ok(error.message.indexOf("Let's crash") >= 0, "Wrong message: " + error.message); }); }); it('plugin register promise reject', function () { @@ -86,8 +86,8 @@ describe('Plugin', function () { }); return plugin.load().then(function () { assert.false("expected error"); - }, function (error) { - assert.ok(error.message.indexOf("Let's reject") >= 0); + }).catch( function (error) { + assert.ok(error.message.indexOf("Let's reject") >= 0, "Wrong message: " + error.message); }); }); }); diff --git a/frontend-js/testFiles/apiCalls/plugins/POST_hash=273dffdc94ef22531b90fb4489ba00c3&name=plugin%20with%20promise&url=.%2FtestFiles%2Fplugin-invalid%2Fresult-promise-crash.js&version=0.0.1&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/plugins/POST_hash=273dffdc94ef22531b90fb4489ba00c3&name=plugin%20with%20promise&url=.%2FtestFiles%2Fplugin-invalid%2Fresult-promise-crash.js&version=0.0.1&token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000..ef54c70241 --- /dev/null +++ b/frontend-js/testFiles/apiCalls/plugins/POST_hash=273dffdc94ef22531b90fb4489ba00c3&name=plugin%20with%20promise&url=.%2FtestFiles%2Fplugin-invalid%2Fresult-promise-crash.js&version=0.0.1&token=MOCK_TOKEN_ID& @@ -0,0 +1,8 @@ +{ + "hash": "273dffdc94ef22531b90fb4489ba00c3", + "name": "plugin with promise", + "urls": [ + "./testFiles/plugin-invalid/result-promise-crash.js" + ], + "version": "0.0.1" +} \ No newline at end of file diff --git a/frontend-js/testFiles/apiCalls/plugins/POST_hash=c36d817fb1e6c3a7b569ee9ba55baa76&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_javascript.js&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/plugins/POST_hash=c36d817fb1e6c3a7b569ee9ba55baa76&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_javascript.js&token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000..d761df0e38 --- /dev/null +++ b/frontend-js/testFiles/apiCalls/plugins/POST_hash=c36d817fb1e6c3a7b569ee9ba55baa76&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_javascript.js&token=MOCK_TOKEN_ID& @@ -0,0 +1,8 @@ +{ + "hash": "c36d817fb1e6c3a7b569ee9ba55baa76", + "name": "", + "urls": [ + "./testFiles/plugin-invalid/invalid_javascript.js" + ], + "version": "" +} \ No newline at end of file diff --git a/frontend-js/testFiles/apiCalls/plugins/POST_hash=d5d652ac0e0f6467d4cb6a742f99d3f7&name=test%20plugin&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_register.js&version=0.0.1&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/plugins/POST_hash=d5d652ac0e0f6467d4cb6a742f99d3f7&name=test%20plugin&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_register.js&version=0.0.1&token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000..02a0838194 --- /dev/null +++ b/frontend-js/testFiles/apiCalls/plugins/POST_hash=d5d652ac0e0f6467d4cb6a742f99d3f7&name=test%20plugin&url=.%2FtestFiles%2Fplugin-invalid%2Finvalid_register.js&version=0.0.1&token=MOCK_TOKEN_ID& @@ -0,0 +1,8 @@ +{ + "hash": "d5d652ac0e0f6467d4cb6a742f99d3f7", + "name": "test plugin", + "urls": [ + "./testFiles/plugin-invalid/invalid_register.js" + ], + "version": "0.0.1" +} \ No newline at end of file -- GitLab