diff --git a/src/bg/user-script-install.js b/src/bg/user-script-install.js index fbc9bea78..b8c8a81ef 100755 --- a/src/bg/user-script-install.js +++ b/src/bg/user-script-install.js @@ -2,7 +2,7 @@ (function() { /// Receive a UserScriptInstall message. -window.onUserScriptInstall = async function(message, sender) { +window.onUserScriptInstall = function(message, sender) { if (message.details) { let downloader = new Downloader(message.details, sender); downloader.start(function() { @@ -11,7 +11,20 @@ window.onUserScriptInstall = async function(message, sender) { } }); } else if (message.source) { - return await UserScriptRegistry.installFromSource(message.source); + // Returning a promise + return UserScriptRegistry.installFromSource(message.source) + .catch(err => { + if (err instanceof ParseError) { + console.warn(err); + chrome.notifications.create({ + 'type': 'basic', + 'title': 'Failed to import script', + 'message': err.message, + }); + } + // Propagate to the message listener + throw err; + }); } } diff --git a/src/bg/user-script-registry.js b/src/bg/user-script-registry.js index 49ae8b9dc..611f3d118 100644 --- a/src/bg/user-script-registry.js +++ b/src/bg/user-script-registry.js @@ -89,7 +89,12 @@ async function installFromSource(source) { console.error('Error looking up script!', event); }; } catch (e) { - console.error('at installFromSource(), db fail:', e); + if (e instanceof ParseError) { + // Noop, will be handled by caller + } else { + console.error('at installFromSource(), db fail:', e); + } + reject(e); } }); }); diff --git a/src/content/import/import-script.js b/src/content/import/import-script.js index 426331939..0fa612c34 100644 --- a/src/content/import/import-script.js +++ b/src/content/import/import-script.js @@ -14,7 +14,12 @@ function onImportUserScript(event) { // Done loading chrome.runtime.sendMessage( {'name': 'UserScriptInstall', 'source': fr.result}, - uuid => openUserScriptEditor(uuid)); + uuid => { + // TODO: When switching to promises use `.catch` + if (!chrome.runtime.lastError) { + openUserScriptEditor(uuid); + } + }); } }; fr.readAsText(importScript.files[0]);