From 37af0504de9b708dbd227a7492eb4d4df2ab1cbd Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 15:41:29 +0100 Subject: [PATCH 1/7] error tracker --- .../client/source/class/osparc/Application.js | 1 + .../class/osparc/ConsoleErrorTracker.js | 51 +++++++ .../class/osparc/tester/ConsoleErrors.js | 129 ++++++++++++++++++ .../class/osparc/tester/TesterCenter.js | 12 +- 4 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js create mode 100644 services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js diff --git a/services/static-webserver/client/source/class/osparc/Application.js b/services/static-webserver/client/source/class/osparc/Application.js index 0b18c01bd22..251b74d42aa 100644 --- a/services/static-webserver/client/source/class/osparc/Application.js +++ b/services/static-webserver/client/source/class/osparc/Application.js @@ -70,6 +70,7 @@ qx.Class.define("osparc.Application", { // trackers osparc.announcement.Tracker.getInstance().startTracker(); osparc.WindowSizeTracker.getInstance().startTracker(); + osparc.ConsoleErrorTracker.getInstance().startTracker(); const webSocket = osparc.wrapper.WebSocket.getInstance(); webSocket.addListener("connect", () => osparc.WatchDog.getInstance().setOnline(true)); diff --git a/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js b/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js new file mode 100644 index 00000000000..78ddb2ab512 --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js @@ -0,0 +1,51 @@ +/* ************************************************************************ + + osparc - the simcore frontend + + https://osparc.io + + Copyright: + 2023 IT'IS Foundation, https://itis.swiss + + License: + MIT: https://opensource.org/licenses/MIT + + Authors: + * Odei Maiz (odeimaiz) + +************************************************************************ */ + +qx.Class.define("osparc.ConsoleErrorTracker", { + extend: qx.core.Object, + type: "singleton", + + construct: function() { + this.base(arguments); + + this.__errors = []; + }, + + members: { + __errors: null, + + startTracker: function() { + const originalConsoleError = console.error; + + // Override console.error + console.error = (...args) => { + // Store the error in the array + this.__errors.push({ + date: new Date(), + error: args + }); + + // Call the original console.error so the error still appears in the console + originalConsoleError.apply(console, args); + }; + }, + + getErrors: function() { + return this.__errors; + }, + } +}); diff --git a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js new file mode 100644 index 00000000000..2c541220baa --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js @@ -0,0 +1,129 @@ +/* ************************************************************************ + + osparc - the simcore frontend + + https://osparc.io + + Copyright: + 2024 IT'IS Foundation, https://itis.swiss + + License: + MIT: https://opensource.org/licenses/MIT + + Authors: + * Odei Maiz (odeimaiz) + +************************************************************************ */ + +qx.Class.define("osparc.tester.ConsoleErrors", { + extend: osparc.po.BaseView, + construct: function() { + this.base(arguments); + }, + + members: { + _createChildControlImpl: function(id) { + let control; + switch (id) { + case "filter-message": { + control = new qx.ui.form.TextField().set({ + liveUpdate : true, + placeholder: this.tr("Search in Message"), + }); + this._add(control); + break; + } + case "messages-table": { + const tableModel = new qx.ui.table.model.Filtered(); + tableModel.setColumns([ + this.tr("Date"), + this.tr("Message"), + ]); + const custom = { + tableColumnModel: function(obj) { + return new qx.ui.table.columnmodel.Resize(obj); + } + }; + control = new qx.ui.table.Table(tableModel, custom).set({ + selectable: true, + statusBarVisible: false, + showCellFocusIndicator: false, + forceLineHeight: false + }); + control.getTableColumnModel().setDataCellRenderer( + 0, + new qx.ui.table.cellrenderer.String().set({ + defaultCellStyle: "user-select: text" + }) + ); + control.getTableColumnModel().setDataCellRenderer( + 1, + new osparc.ui.table.cellrenderer.Html().set({ + defaultCellStyle: "user-select: text; text-wrap: wrap" + }) + ); + control.setColumnWidth(0, 80); + + control.setDataRowRenderer(new osparc.ui.table.rowrenderer.ExpandSelection(control)); + this._add(control, { + flex: 1 + }); + break; + } + case "json-viewer": + control = new osparc.ui.basic.JsonTreeWidget(); + this._add(control); + break; + } + return control || this.base(arguments, id); + }, + + _buildLayout: function() { + const filterMessage = this.getChildControl("filter-message"); + const table = this.getChildControl("messages-table"); + const jsonViewer = this.getChildControl("json-viewer"); + + const model = table.getTableModel(); + filterMessage.addListener("changeValue", e => { + const value = e.getData(); + model.resetHiddenRows(); + model.addNotRegex(value, "Message", true); + model.applyFilters(); + }); + table.addListener("cellTap", e => { + const selectedRow = e.getRow(); + const rowData = table.getTableModel().getRowData(selectedRow); + jsonViewer.setJson(JSON.parse(rowData[2])); + }, this); + + this.__populateTable(); + }, + + __populateTable: function() { + const consoleErrorTracker = osparc.ConsoleErrorTracker.getInstance(); + const messagesObj = consoleErrorTracker.getCachedMessages(); + const messagesArray = []; + for (const channel in messagesObj) { + messagesObj[channel].forEach(msg => { + messagesArray.push({ + date: msg.date, + message: msg.message, + }); + }); + } + messagesArray.sort((a, b) => { + return new Date(b.date) - new Date(a.date); // newest first + }); + const datas = []; + messagesArray.forEach(entry => { + const data = [ + new Date(entry.date).toLocaleTimeString(), + entry.channel, + JSON.stringify(entry.message), + ]; + datas.push(data); + }); + this.getChildControl("messages-table").getTableModel().setData(datas); + } + } +}); diff --git a/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js b/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js index b456afebb32..e4a3cb6f870 100644 --- a/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js +++ b/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js @@ -27,6 +27,7 @@ qx.Class.define("osparc.tester.TesterCenter", { this.addWidgetOnTopOfTheTabs(miniProfile); this.__addSocketMessagesPage(); + this.__addConsoleErrorsPage(); this.__addStaticsPage(); }, @@ -34,8 +35,15 @@ qx.Class.define("osparc.tester.TesterCenter", { __addSocketMessagesPage: function() { const title = this.tr("Socket Messages"); const iconSrc = "@FontAwesome5Solid/exchange-alt/22"; - const maintenance = new osparc.tester.WebSocketMessages(); - this.addTab(title, iconSrc, maintenance); + const webSocketMessages = new osparc.tester.WebSocketMessages(); + this.addTab(title, iconSrc, webSocketMessages); + }, + + __addConsoleErrorsPage: function() { + const title = this.tr("Socket Messages"); + const iconSrc = "@FontAwesome5Solid/exchange-alt/22"; + const consoleErrors = new osparc.tester.ConsoleErrors(); + this.addTab(title, iconSrc, consoleErrors); }, __addStaticsPage: function() { From 3aaf879975b4c96ce766650b8384b70ad7b748c5 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 15:46:46 +0100 Subject: [PATCH 2/7] minor --- .../client/source/class/osparc/navigation/UserMenu.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/static-webserver/client/source/class/osparc/navigation/UserMenu.js b/services/static-webserver/client/source/class/osparc/navigation/UserMenu.js index 213bc8bf0bd..e4798ed1464 100644 --- a/services/static-webserver/client/source/class/osparc/navigation/UserMenu.js +++ b/services/static-webserver/client/source/class/osparc/navigation/UserMenu.js @@ -213,6 +213,9 @@ qx.Class.define("osparc.navigation.UserMenu", { if (osparc.data.Permissions.getInstance().isProductOwner()) { this.getChildControl("po-center"); } + if (osparc.data.Permissions.getInstance().isTester()) { + this.getChildControl("tester-center"); + } if (osparc.desktop.credits.Utils.areWalletsEnabled()) { this.getChildControl("billing-center"); } From 69f407ba27f99058e115741b280902693903987f Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 15:55:22 +0100 Subject: [PATCH 3/7] print error --- .../class/osparc/tester/ConsoleErrors.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js index 2c541220baa..30b21649fda 100644 --- a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js +++ b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js @@ -64,14 +64,14 @@ qx.Class.define("osparc.tester.ConsoleErrors", { ); control.setColumnWidth(0, 80); - control.setDataRowRenderer(new osparc.ui.table.rowrenderer.ExpandSelection(control)); + // control.setDataRowRenderer(new osparc.ui.table.rowrenderer.ExpandSelection(control)); this._add(control, { flex: 1 }); break; } - case "json-viewer": - control = new osparc.ui.basic.JsonTreeWidget(); + case "error-viewer": + control = new qx.ui.form.TextArea(); this._add(control); break; } @@ -81,7 +81,7 @@ qx.Class.define("osparc.tester.ConsoleErrors", { _buildLayout: function() { const filterMessage = this.getChildControl("filter-message"); const table = this.getChildControl("messages-table"); - const jsonViewer = this.getChildControl("json-viewer"); + const errorViewer = this.getChildControl("error-viewer"); const model = table.getTableModel(); filterMessage.addListener("changeValue", e => { @@ -93,7 +93,7 @@ qx.Class.define("osparc.tester.ConsoleErrors", { table.addListener("cellTap", e => { const selectedRow = e.getRow(); const rowData = table.getTableModel().getRowData(selectedRow); - jsonViewer.setJson(JSON.parse(rowData[2])); + errorViewer.setValue(JSON.stringify(rowData[1])); }, this); this.__populateTable(); @@ -101,25 +101,22 @@ qx.Class.define("osparc.tester.ConsoleErrors", { __populateTable: function() { const consoleErrorTracker = osparc.ConsoleErrorTracker.getInstance(); - const messagesObj = consoleErrorTracker.getCachedMessages(); - const messagesArray = []; - for (const channel in messagesObj) { - messagesObj[channel].forEach(msg => { - messagesArray.push({ - date: msg.date, - message: msg.message, - }); + const errors = consoleErrorTracker.getErrors(); + const errorsArray = []; + errors.forEach(msg => { + errorsArray.push({ + date: msg.date, + message: msg.error, }); - } - messagesArray.sort((a, b) => { + }); + errorsArray.sort((a, b) => { return new Date(b.date) - new Date(a.date); // newest first }); const datas = []; - messagesArray.forEach(entry => { + errorsArray.forEach(entry => { const data = [ new Date(entry.date).toLocaleTimeString(), - entry.channel, - JSON.stringify(entry.message), + entry.message, ]; datas.push(data); }); From 305ede28e85ee17f22f5cbe0fbaa6705a87f5b69 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 15:58:48 +0100 Subject: [PATCH 4/7] aesthetics --- .../client/source/class/osparc/tester/ConsoleErrors.js | 4 +++- .../client/source/class/osparc/tester/TesterCenter.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js index 30b21649fda..49fbe1cefd8 100644 --- a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js +++ b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js @@ -72,7 +72,9 @@ qx.Class.define("osparc.tester.ConsoleErrors", { } case "error-viewer": control = new qx.ui.form.TextArea(); - this._add(control); + this._add(control, { + flex: 1 + }); break; } return control || this.base(arguments, id); diff --git a/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js b/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js index e4a3cb6f870..8335daaffdf 100644 --- a/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js +++ b/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js @@ -40,8 +40,8 @@ qx.Class.define("osparc.tester.TesterCenter", { }, __addConsoleErrorsPage: function() { - const title = this.tr("Socket Messages"); - const iconSrc = "@FontAwesome5Solid/exchange-alt/22"; + const title = this.tr("Console errors"); + const iconSrc = "@FontAwesome5Solid/circle-xmark/22"; const consoleErrors = new osparc.tester.ConsoleErrors(); this.addTab(title, iconSrc, consoleErrors); }, From 091f2b48c32e5155efde0e129901a1676976a9c9 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 16:01:30 +0100 Subject: [PATCH 5/7] minor --- .../client/source/class/osparc/tester/ConsoleErrors.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js index 49fbe1cefd8..074acc0315f 100644 --- a/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js +++ b/services/static-webserver/client/source/class/osparc/tester/ConsoleErrors.js @@ -71,7 +71,9 @@ qx.Class.define("osparc.tester.ConsoleErrors", { break; } case "error-viewer": - control = new qx.ui.form.TextArea(); + control = new qx.ui.form.TextArea().set({ + autoSize: true, + }); this._add(control, { flex: 1 }); From 7e03659e75af9960e1cc6bfdd24371a3203c95b0 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 16:04:55 +0100 Subject: [PATCH 6/7] icon --- .../client/source/class/osparc/tester/TesterCenter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js b/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js index 8335daaffdf..023fafb4dc5 100644 --- a/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js +++ b/services/static-webserver/client/source/class/osparc/tester/TesterCenter.js @@ -40,8 +40,8 @@ qx.Class.define("osparc.tester.TesterCenter", { }, __addConsoleErrorsPage: function() { - const title = this.tr("Console errors"); - const iconSrc = "@FontAwesome5Solid/circle-xmark/22"; + const title = this.tr("Console Errors"); + const iconSrc = "@FontAwesome5Solid/times/22"; const consoleErrors = new osparc.tester.ConsoleErrors(); this.addTab(title, iconSrc, consoleErrors); }, From 29af7aa6859ac059ea83ee382ee8a3a11f53efce Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 16:07:47 +0100 Subject: [PATCH 7/7] keep last 20 --- .../client/source/class/osparc/ConsoleErrorTracker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js b/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js index 78ddb2ab512..6da6cdefc4e 100644 --- a/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js +++ b/services/static-webserver/client/source/class/osparc/ConsoleErrorTracker.js @@ -33,11 +33,13 @@ qx.Class.define("osparc.ConsoleErrorTracker", { // Override console.error console.error = (...args) => { - // Store the error in the array - this.__errors.push({ + this.__errors.unshift({ date: new Date(), error: args }); + if (this.__errors.length > 20) { + this.__errors.length = 20; + } // Call the original console.error so the error still appears in the console originalConsoleError.apply(console, args);