From 9c21523215f390b0dc73b432c84aa7fd365cb290 Mon Sep 17 00:00:00 2001 From: Zhizhen He Date: Sun, 18 Oct 2026 15:48:36 +0800 Subject: [PATCH] action: Report parsing errors to remote control clients --- docs/changelog.rst | 3 +++ kitty/boss.py | 2 ++ kitty_tests/remote_control.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6644747bb..b402d7a90 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -523,6 +523,9 @@ Detailed list of changes - Kittens: Reject command-line options missing their required value instead of silently ignoring them (:pull:`10687`) +- Remote control: Fix :ref:`at-action` reporting success when the action's + arguments cannot be parsed. + 0.49.2 [2026-10-01] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index 27f4edf5c..a223bab8e 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -2106,6 +2106,8 @@ class Boss: try: actions = get_options().alias_map.resolve_aliases(action_definition, MapType.MAP if dispatch_type == 'KeyPress' else MapType.MOUSE_MAP) except Exception as e: + if raise_error: + raise self.show_error('Failed to parse action', f'{action_definition}\n{e}') return True if actions: diff --git a/kitty_tests/remote_control.py b/kitty_tests/remote_control.py index 2fa2e8aab..d52e25e01 100644 --- a/kitty_tests/remote_control.py +++ b/kitty_tests/remote_control.py @@ -4,6 +4,7 @@ import os import subprocess import tempfile +from types import MethodType from unittest.mock import Mock, patch from kitty.constants import kitty_exe @@ -37,6 +38,35 @@ class Boss: class TestRemoteControl(BaseTest): + def test_action_parse_errors(self): + from kitty.boss import Boss as KittyBoss + from kitty.rc.base import RemoteControlErrorWithoutTraceback + from kitty.remote_control import handle_cmd + + self.set_options() + for action in ('goto_tab not-a-number', 'set_font_size invalid', 'unknown_action argument', 'goto_tab 1'): + with self.subTest(action=action): + boss = Mock(active_window=None, window_for_dispatch=None, dispatch_action=Mock(return_value=True)) + boss.combine = MethodType(KittyBoss.combine, boss) + request = {'cmd': 'action', 'version': [0, 26, 0], 'payload': {'action': action}} + if action == 'goto_tab 1': + self.ae(handle_cmd(boss, None, request, 0, None), {'ok': True}) + boss.dispatch_action.assert_called_once() + else: + with self.assertRaises(RemoteControlErrorWithoutTraceback): + handle_cmd(boss, None, request, 0, None) + boss.dispatch_action.assert_not_called() + boss.show_error.assert_not_called() + + def test_combine_parse_error_reporting(self): + from kitty.boss import Boss as KittyBoss + + self.set_options() + boss = Mock() + self.assertTrue(KittyBoss.combine(boss, 'goto_tab not-a-number')) + boss.show_error.assert_called_once() + boss.dispatch_action.assert_not_called() + def test_select_window_exclude_active(self): from kitty.boss import Boss as KittyBoss