From 1d1d55e2b4daa8028bd632c2340189a69fc8a552 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 Oct 2021 05:10:59 +0530 Subject: [PATCH] Fix #4084 --- kitty/rc/base.py | 4 ++++ kitty/rc/set_colors.py | 9 ++++++--- kitty/remote_control.py | 10 ++++++---- kitty/shell.py | 6 +++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/kitty/rc/base.py b/kitty/rc/base.py index cf9e51587..1e20bd4e5 100644 --- a/kitty/rc/base.py +++ b/kitty/rc/base.py @@ -105,6 +105,10 @@ active tab, one the previously active tab and so on. ''' +class ParsingOfArgsFailed(ValueError): + pass + + class RemoteCommand: name: str = '' diff --git a/kitty/rc/set_colors.py b/kitty/rc/set_colors.py index c9aa95643..d7a93ab3a 100644 --- a/kitty/rc/set_colors.py +++ b/kitty/rc/set_colors.py @@ -11,8 +11,8 @@ from kitty.fast_data_types import patch_color_profiles from kitty.rgb import Color from .base import ( - MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, PayloadGetType, - PayloadType, RCOptions, RemoteCommand, ResponseType, Window + MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, ParsingOfArgsFailed, + PayloadGetType, PayloadType, RCOptions, RemoteCommand, ResponseType, Window ) if TYPE_CHECKING: @@ -76,7 +76,10 @@ this option, any color arguments are ignored and --configured and --all are impl final_colors: Dict[str, int] = {} cursor_text_color: Optional[Union[int, bool]] = False if not opts.reset: - final_colors, cursor_text_color = parse_colors(args) + try: + final_colors, cursor_text_color = parse_colors(args) + except Exception as err: + raise ParsingOfArgsFailed(str(err)) from err ans = { 'match_window': opts.match, 'match_tab': opts.match_tab, 'all': opts.all or opts.reset, 'configured': opts.configured or opts.reset, diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 484972c94..f91b4a44d 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -10,8 +10,7 @@ import types from contextlib import suppress from functools import partial from typing import ( - Any, Dict, Generator, Iterable, List, Optional, Tuple, - Union, cast + Any, Dict, Generator, Iterable, List, Optional, Tuple, Union, cast ) from .cli import emph, parse_args @@ -19,7 +18,7 @@ from .cli_stub import RCOptions from .constants import appname, version from .fast_data_types import read_command_response from .rc.base import ( - PayloadGetter, all_command_names, command_for_name, + ParsingOfArgsFailed, PayloadGetter, all_command_names, command_for_name, no_response as no_response_sentinel, parse_subcommand_cli ) from .typing import BossType, WindowType @@ -177,7 +176,10 @@ def main(args: List[str]) -> None: raise SystemExit('{} is not a known command. Known commands are: {}'.format( emph(cmd), ', '.join(x.replace('_', '-') for x in all_command_names()))) opts, items = parse_subcommand_cli(c, items) - payload = c.message_to_kitty(global_opts, opts, items) + try: + payload = c.message_to_kitty(global_opts, opts, items) + except ParsingOfArgsFailed as err: + exit(str(err)) if global_opts.no_command_response is not None: no_response = global_opts.no_command_response # type: ignore else: diff --git a/kitty/shell.py b/kitty/shell.py index f66d53119..2512a7866 100644 --- a/kitty/shell.py +++ b/kitty/shell.py @@ -16,9 +16,9 @@ from .cli import ( title ) from .cli_stub import RCOptions -from .constants import cache_dir, version, kitty_face +from .constants import cache_dir, kitty_face, version from .rc.base import ( - RemoteCommand, all_command_names, command_for_name, + ParsingOfArgsFailed, RemoteCommand, all_command_names, command_for_name, display_subcommand_help, parse_subcommand_cli ) from .types import run_once @@ -205,7 +205,7 @@ def real_main(global_opts: RCOptions) -> None: else: try: run_cmd(global_opts, cmd, func, opts, items) - except SystemExit as e: + except (SystemExit, ParsingOfArgsFailed) as e: print_err(e) continue except KeyboardInterrupt: