summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-08 21:33:10 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-08 22:38:05 -0400
commitc5d6b9452d1bfa51a5fef9a19082d115ef180a9b (patch)
tree17f9a1bdd2b09937b776127a1764a3c9067082cf /ext
parent6a6e200ef947b92576351e39fc30b6653a576d70 (diff)
Create utility function for logging errors
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/search.js2
-rw-r--r--ext/fg/js/float.js2
-rw-r--r--ext/fg/js/frontend.js2
-rw-r--r--ext/mixed/js/extension.js18
4 files changed, 21 insertions, 3 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 52adab16..ead9ba6f 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -53,7 +53,7 @@ class DisplaySearch extends Display {
}
onError(error) {
- window.alert(`Error: ${error.toString ? error.toString() : error}`);
+ logError(error, true);
}
onSearchClear() {
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 88842eef..8fdb6925 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -37,7 +37,7 @@ class DisplayFloat extends Display {
if (window.yomichan_orphaned) {
this.onOrphaned();
} else {
- window.alert(`Error: ${error.toString ? error.toString() : error}`);
+ logError(error, true);
}
}
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 39433afb..88cb93a9 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -228,7 +228,7 @@ class Frontend {
}
onError(error) {
- console.log(error);
+ logError(error, false);
}
setEnabled(enabled) {
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'))