diff --git a/addons/api/addon/handlers/cache-daemon-handler.js b/addons/api/addon/handlers/cache-daemon-handler.js index d712df086..6761d23ce 100644 --- a/addons/api/addon/handlers/cache-daemon-handler.js +++ b/addons/api/addon/handlers/cache-daemon-handler.js @@ -3,13 +3,14 @@ * SPDX-License-Identifier: BUSL-1.1 */ -/* global __electronLog */ import { inject as service } from '@ember/service'; import { getOwner, setOwner } from '@ember/application'; import { generateMQLExpression } from '../utils/mql-query'; import { paginateResults } from '../utils/paginate-results'; import { underscore } from '@ember/string'; +const { __electronLog } = globalThis; + /** * Not all types are yet supported by the cache daemon so we'll * just whitelist the ones we need to start with. Keys are the resource diff --git a/addons/core/addon/decorators/notify.js b/addons/core/addon/decorators/notify.js index 751764454..de76391fa 100644 --- a/addons/core/addon/decorators/notify.js +++ b/addons/core/addon/decorators/notify.js @@ -5,6 +5,8 @@ import { getOwner } from '@ember/application'; +const { __electronLog } = globalThis; + /** * Decorates a method and, if the method does not error, shows a success * notification via the notify service. The text of the notification is derived @@ -50,10 +52,17 @@ export function notifySuccess(notification) { * * @param {string|function} notification * @param {object} options - * @param {object} options.sticky - defaults to true, whether or not to persist + * @param {boolean} options.sticky - defaults to true, whether or not to persist * the notification until user dismissal - * @param {object} options.catch - defaults to false, whether or not to catch + * @param {boolean} options.catch - defaults to false, whether or not to catch * and squelch the error + * @param {object} options.log - defaults to undefined, object with unique + * information about the error to send to our + * electron logging service + * @param {string} options.log.origin - defaults to undefined, the origin that + * triggered the error + * @param {string} options.log.level - defaults to undefined, the log level that + * our electron logging service should use */ export function notifyError( notification, @@ -69,6 +78,10 @@ export function notifyError( try { return await method.apply(this, arguments); } catch (error) { + if (options.log) { + const { origin, level = 'error' } = options.log; + __electronLog?.[level](`${origin}:`, error.message); + } const candidateKey = typeof notification === 'function' ? notification.apply(this, [error]) diff --git a/ui/desktop/.eslintrc.js b/ui/desktop/.eslintrc.js index 384b9c895..b38f0e03a 100644 --- a/ui/desktop/.eslintrc.js +++ b/ui/desktop/.eslintrc.js @@ -25,7 +25,6 @@ module.exports = { env: { browser: true, }, - globals: { __electronLog: 'true' }, rules: { 'ember/no-get': 'off', 'ember/no-get-with-default': 'off', diff --git a/ui/desktop/app/controllers/cluster-url.js b/ui/desktop/app/controllers/cluster-url.js index 6da120b79..78ae52e96 100644 --- a/ui/desktop/app/controllers/cluster-url.js +++ b/ui/desktop/app/controllers/cluster-url.js @@ -26,6 +26,7 @@ export default class ClusterUrlController extends Controller { @loading @notifyError(() => 'errors.cluster-url-verification-failed.description', { catch: true, + log: { origin: 'setClusterUrl' }, }) async setClusterUrl(clusterUrl) { await this.clusterUrlService.setClusterUrl(clusterUrl); diff --git a/ui/desktop/app/routes/application.js b/ui/desktop/app/routes/application.js index b939cd0ff..d6b796f0f 100644 --- a/ui/desktop/app/routes/application.js +++ b/ui/desktop/app/routes/application.js @@ -29,7 +29,10 @@ export default class ApplicationRoute extends Route { * reported by the main process. If they differ, update the main process * clusterUrl so that the renderer's CSP can be rewritten to allow requests. */ - @notifyError(({ message }) => message, { catch: true }) + @notifyError(({ message }) => message, { + catch: true, + log: { origin: 'ApplicationRoute:beforeModel' }, + }) async beforeModel() { this.intl.setLocale(['en-us']); await this.session.setup(); diff --git a/ui/desktop/app/routes/scopes/scope/projects.js b/ui/desktop/app/routes/scopes/scope/projects.js index 736c8a190..bbbe26d42 100644 --- a/ui/desktop/app/routes/scopes/scope/projects.js +++ b/ui/desktop/app/routes/scopes/scope/projects.js @@ -6,6 +6,8 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +const { __electronLog } = globalThis; + /** * TODO: This route is now vestigial. Desktop does not provide project-based * navigation. This route formerly provided a way to aggregate diff --git a/ui/desktop/app/routes/scopes/scope/projects/sessions/session.js b/ui/desktop/app/routes/scopes/scope/projects/sessions/session.js index 2fe6171ef..b6a813ca3 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/sessions/session.js +++ b/ui/desktop/app/routes/scopes/scope/projects/sessions/session.js @@ -6,6 +6,8 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +const { __electronLog } = globalThis; + export default class ScopesScopeProjectsSessionsSessionRoute extends Route { // =services diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/index.js b/ui/desktop/app/routes/scopes/scope/projects/targets/index.js index 24011ddd0..0cb6e0d7a 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/index.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/index.js @@ -11,6 +11,8 @@ import { } from 'api/models/session'; import { action } from '@ember/object'; +const { __electronLog } = globalThis; + export default class ScopesScopeProjectsTargetsIndexRoute extends Route { // =services diff --git a/ui/desktop/app/services/cluster-url.js b/ui/desktop/app/services/cluster-url.js index 641f7134f..fd7f26f88 100644 --- a/ui/desktop/app/services/cluster-url.js +++ b/ui/desktop/app/services/cluster-url.js @@ -88,7 +88,10 @@ export default class ClusterUrlService extends Service { /** * Resets the clusterUrl. */ - @notifyError(({ message }) => message, { catch: true }) + @notifyError(({ message }) => message, { + catch: true, + log: { origin: 'resetClusterUrl' }, + }) async resetClusterUrl() { this.rendererClusterUrl = null; await this.ipc.invoke('resetClusterUrl');