Skip to content

Handle Click exceptions by hand#1714

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/manual-click-exception-handling
Open

Handle Click exceptions by hand#1714
rolandwalker wants to merge 1 commit intomainfrom
RW/manual-click-exception-handling

Conversation

@rolandwalker
Copy link
Contributor

Description

Handle Click exceptions by hand, creating a main() function which handles Click's exceptions and returns an integer, or exits.

Per the documentation at

we need to catch click.Abort and click.ClickException, but BrokenPipeError was also added.

Recast the cli() function as click_entrypoint() to help differentiate it from run_cli(). The latter one could even be renamed to run_repl()!

Motivation: prompt_toolkit is already handling exceptions such as KeyboardInterrupt. We had two layers trying to handle exceptions transparently, and we want control-c to cancel pending queries very reliably. Let's start to untangle.

This also exposes the arguments to be processed by Click, which is desirable in case we want to pre-process them. Example: mycli -h could print the helpdoc, instead of being interpreted as a missing hostname. Example: we could catch some issues with --password before running Click.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Mar 16, 2026
@github-actions
Copy link

I can’t complete a real review yet because I can’t read the repo in this session: all shell commands fail with bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted.

Please paste one of these, and I’ll review immediately:

  1. git diff --unified=3 77a3fe5d7f8b1a1814c9ab4e4b30cab535959a6e...b3bdb16f1acef1b1e8b7307caf527a03ec9e618d
  2. Or the changed files’ patches from PR Handle Click exceptions by hand #1714.

Once you share that, I’ll return concise findings focused on correctness regressions, security, and missing tests/edge cases only.

@rolandwalker rolandwalker mentioned this pull request Mar 16, 2026
3 tasks
@rolandwalker rolandwalker force-pushed the RW/manual-click-exception-handling branch from b3bdb16 to cd2ef3c Compare March 16, 2026 21:01
creating a main() function which handles Click's exceptions and returns
an integer, or exits.

Per the documentation at

 * https://click.palletsprojects.com/en/stable/exceptions/

we need to catch click.Abort and click.ClickException, but
BrokenPipeError was also added.

Recast the cli() function as click_entrypoint() to help differentiate
it from run_cli().  The latter one could even be renamed to run_repl()!

Motivation: prompt_toolkit is already handling exceptions such as
KeyboardInterrupt.  We had two layers trying to handle exceptions
transparently, and we want control-c to cancel pending queries very
reliably.  Let's start to untangle.

This also exposes the arguments to be processed by Click, which is
desirable in case we want to pre-process them.  Example: "mycli -h"
could print the helpdoc, instead of being interpreted as a missing
hostname.  Example: we could catch some issues with --password before
running Click.
@rolandwalker rolandwalker force-pushed the RW/manual-click-exception-handling branch from cd2ef3c to bc703a6 Compare March 16, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant