From c5d6b9452d1bfa51a5fef9a19082d115ef180a9b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 8 Oct 2019 21:33:10 -0400 Subject: Create utility function for logging errors --- ext/mixed/js/extension.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/extension.js b/ext/mixed/js/extension.js index 5e925124..861e52a5 100644 --- a/ext/mixed/js/extension.js +++ b/ext/mixed/js/extension.js @@ -68,6 +68,24 @@ function jsonToError(jsonError) { return error; } +function logError(error, alert) { + const manifest = chrome.runtime.getManifest(); + let errorMessage = `${manifest.name} v${manifest.version} has encountered an error.\n`; + errorMessage += `Originating URL: ${window.location.href}\n`; + + const errorString = `${error.toString ? error.toString() : error}`; + const stack = `${error.stack}`.trimRight(); + errorMessage += (!stack.startsWith(errorString) ? `${errorString}\n${stack}` : `${stack}`); + + errorMessage += '\n\nIssues can be reported at https://github.com/FooSoft/yomichan/issues'; + + console.error(errorMessage); + + if (alert) { + window.alert(`${errorString}\n\nCheck the developer console for more details.`); + } +} + const EXTENSION_IS_BROWSER_EDGE = ( extensionHasBrowser() && (!extensionHasChrome() || (typeof chrome.runtime === 'undefined' && typeof browser.runtime !== 'undefined')) -- cgit v1.2.3