mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-23 00:24:53 +00:00
Fall back when launch wrapper context setup fails
Building LaunchContext resolves the configured shell. Catch that failure at the launch wrapper boundary so an explicit command can still start.
This commit is contained in:
parent
b4b186a6ad
commit
c805a6e2a4
2 changed files with 26 additions and 12 deletions
|
|
@ -120,24 +120,24 @@ def prefix_for_launch(req: LaunchRequest, argv: Sequence[str], cwd: str, env: Ma
|
|||
window_id = int(env.get('KITTY_WINDOW_ID', '0'))
|
||||
except ValueError:
|
||||
window_id = 0
|
||||
ctx = LaunchContext(
|
||||
argv=tuple(argv),
|
||||
cwd=cwd,
|
||||
env=MappingProxyType(dict(env)),
|
||||
is_default_shell=list(argv) == resolved_shell(get_options()),
|
||||
window_id=window_id,
|
||||
launch_type=req.launch_type,
|
||||
source_window_id=req.source_window_id,
|
||||
source_pid=source_pid_for(req.source_window_id),
|
||||
user_vars=MappingProxyType(dict(req.user_vars)),
|
||||
)
|
||||
try:
|
||||
ctx = LaunchContext(
|
||||
argv=tuple(argv),
|
||||
cwd=cwd,
|
||||
env=MappingProxyType(dict(env)),
|
||||
is_default_shell=list(argv) == resolved_shell(get_options()),
|
||||
window_id=window_id,
|
||||
launch_type=req.launch_type,
|
||||
source_window_id=req.source_window_id,
|
||||
source_pid=source_pid_for(req.source_window_id),
|
||||
user_vars=MappingProxyType(dict(req.user_vars)),
|
||||
)
|
||||
ans = func(ctx)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
log_error(f'The {FUNCTION_NAME}() function in {MODULE_NAME} failed with error: {e}, running the command without a wrapper')
|
||||
log_error(f'Failed to apply {MODULE_NAME} with error: {e}, running the command without a wrapper')
|
||||
return ()
|
||||
if ans is None:
|
||||
return ()
|
||||
|
|
|
|||
|
|
@ -534,3 +534,17 @@ read -r _
|
|||
c, exe, argv = self._fork(launch_request=req, user_func=self._recording(empty))
|
||||
self.ae(argv, ('/bin/prog', 'arg'))
|
||||
self.ae(len(errors), 4)
|
||||
|
||||
def test_launch_wrapper_invalid_shell(self):
|
||||
from kitty import launch_wrapper
|
||||
|
||||
self.set_options({'shell': '"unterminated', 'shell_integration': frozenset({'disabled'})})
|
||||
req = launch_wrapper.LaunchRequest('tab')
|
||||
with patch.object(launch_wrapper, 'log_error') as log_error:
|
||||
c, exe, argv = self._fork(launch_request=req, user_func=self._recording(['/bin/wrapper']))
|
||||
self.ae(exe, '/bin/prog')
|
||||
self.ae(argv, ('/bin/prog', 'arg'))
|
||||
self.ae(c.kitty_wrappers, ())
|
||||
self.ae(self.contexts, [])
|
||||
log_error.assert_called_once()
|
||||
self.assertIn('Unterminated string', log_error.call_args.args[0])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue