{"record":{"id":"7953b574bedd2a9c","repo":"kovidgoyal/kitty","slug":"argparse-error-from-systemexit","errorCode":null,"errorMessage":"{argparse error from SystemExit}","messagePattern":"\\{argparse error from SystemExit\\}","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"kitty/launch.py","lineNumber":441,"sourceCode":"\n\n--hold-after-ssh\ntype=bool-set\nWhen using :option:`--cwd`:code:`=current` or similar from a window that is running the ssh kitten,\nthe new window will run a local shell after disconnecting from the remote host, when this option\nis specified.\n\"\"\"\n\n\n# }}}\n\n\ndef parse_launch_args(args: Sequence[str] | None = None) -> LaunchSpec:\n    args = list(args or ())\n    try:\n        opts, args = parse_args(result_class=LaunchCLIOptions, args=args, ospec=options_spec)\n    except SystemExit as e:\n        raise ValueError(str(e)) from e\n    return LaunchSpec(opts, args)\n\n\ndef get_env(opts: LaunchCLIOptions, active_child: Child | None = None, base_env: dict[str, str] | None = None) -> dict[str, str]:\n    env: dict[str, str] = {}\n    if opts.copy_env and active_child:\n        env.update(active_child.foreground_environ)\n    if base_env is not None:\n        env.update(base_env)\n    for x in opts.env:\n        for k, v in parse_env(x, env):\n            env[k] = v\n    return env\n\n\ndef layer_shell_config_from_panel_opts(panel_opts: Iterable[str]) -> LayerShellConfig:\n    from kittens.panel.main import layer_shell_config, parse_panel_args\n","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/launch.py#L423-L459","documentation":"parse_launch_args wraps kitty's option parser; argparse errors normally exit the process, so the SystemExit is caught and re-raised as ValueError carrying argparse's message (e.g. unrecognized arguments, invalid choices).","triggerScenarios":"Any malformed --launch options string passed to launch, add_window, clone-decode, or response_from_kitty: unknown flags, bad value types, missing required values.","commonSituations":"kitty @ launch / remote-control commands with typos in flags; kittens composing launch options programmatically; option removed/renamed across kitty versions.","solutions":["Print/inspect the exact args list passed and compare with kitty launch --help.","Quote CLI strings properly when building them in shell/Python.","After upgrading kitty, re-check option names in the error message."],"exampleFix":"# before\nparse_launch_args(['--typ', 'overlay'])\n# after\nparse_launch_args(['--type', 'overlay'])","handlingStrategy":"try-catch","validationCode":"from kitty.launch import parse_launch_args\n# pre-flight: kitty launch --help equivalent via parse and catch","typeGuard":null,"tryCatchPattern":"try:\n    spec = parse_launch_args(args)\nexcept ValueError as e:\n    show_user_friendly_error(str(e)); return","preventionTips":["Keep option literals in constants to avoid typos.","Re-validate option strings when bumping kitty versions."],"tags":["kitty","launch","argparse","option-validation"],"backgroundTag":"cli-option-validation-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}