diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 5e899aba1..a06fc9361 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1122,7 +1122,7 @@ class CommandDispatcher: try: userscripts.run_async(tab, cmd, *args, win_id=self._win_id, env=env, verbose=verbose) - except userscripts.UnsupportedError as e: + except (userscripts.UnsupportedError, userscripts.NotFoundError) as e: raise cmdexc.CommandError(e) @cmdutils.register(instance='command-dispatcher', scope='window') diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 4601ed528..1cb4f14f4 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -315,6 +315,27 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner): return +class NotFoundError(Exception): + + """Raised when spawning a userscript that doesn't exist. + + Attributes: + script_name: name of the userscript as called + paths: path names that were searched for the userscript + message: descriptive message string of the error + """ + + def __init__(self, script_name, paths=[]): + self.script_name = script_name + self.paths = paths + self.message = "Userscript '" + script_name + "' not found" + if paths: + self.message += " in userscript directory '" + ("' or '".join(paths)) + "'" + + def __str__(self): + return self.message + + class UnsupportedError(Exception): """Raised when userscripts aren't supported on this platform.""" @@ -375,6 +396,13 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False): if not os.path.exists(cmd_path): cmd_path = os.path.join(standarddir.system_data(), "userscripts", cmd) + if not os.path.exists(cmd_path): + raise NotFoundError(cmd, [ + os.path.join(standarddir.data(), "userscripts"), + os.path.join(standarddir.system_data(), "userscripts"), + ]) + elif not os.path.exists(cmd_path): + raise NotFoundError(cmd_path) log.misc.debug("Userscript to run: {}".format(cmd_path)) runner.finished.connect(commandrunner.deleteLater) diff --git a/tests/end2end/features/spawn.feature b/tests/end2end/features/spawn.feature index 5cdeac029..341e6c921 100644 --- a/tests/end2end/features/spawn.feature +++ b/tests/end2end/features/spawn.feature @@ -10,7 +10,11 @@ Feature: :spawn Scenario: Starting a userscript which doesn't exist When I run :spawn -u this_does_not_exist - Then the error "Error while spawning userscript: The process failed to start." should be shown + Then regex "Userscript 'this_does_not_exist' not found in userscript directory '(.*)'( or '(.*)')*" should be logged + + Scenario: Starting a userscript with absoloute path which doesn't exist + When I run :spawn -u /this_does_not_exist + Then the error "Userscript '/this_does_not_exist' not found" should be shown # https://github.com/The-Compiler/qutebrowser/issues/1614 @posix