parent
80b5c9127e
commit
8eb12c6cb9
@ -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')
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user