Commit 6ae424de authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Make really sure we show an error message in case saving failed

When the extension is reloaded, its context is invalidated and any call to an extension API would just throw.
Catch the most important bits of error reporting on save, so you're not left wondering why your settings don't change.

Differential Revision: https://phabricator.kde.org/D20819
parent cf1c09ff
......@@ -100,9 +100,14 @@ function saveSettings(cb) {
// TODO save additional stuff if we have it
}
storage.set(settings, function () {
return cb(chrome.runtime.lastError);
});
try {
storage.set(settings, function () {
return cb(chrome.runtime.lastError);
});
// When the extension is reloaded, any call to extension APIs throws
} catch (e) {
cb(e);
}
}
document.addEventListener("DOMContentLoaded", function () {
......@@ -162,7 +167,12 @@ document.addEventListener("DOMContentLoaded", function () {
saveSettings(function (error) {
if (error) {
saveMessage.innerText = chrome.i18n.getMessage("options_save_failed");
try {
saveMessage.innerText = chrome.i18n.getMessage("options_save_failed");
} catch (e) {
// When the extension is reloaded, any call to extension APIs throws, make sure we show at least some form of error
saveMessage.innerText = "Saving settings failed (" + (error || e) + ")";
}
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment