Expose ClickException and UsageError from the typer namespace

Closed
UT
4mo ago
+26-0

Summary

Closes #1867.

After vendoring Click in 0.26.0, Typer re-exports several vendored exception types — typer.BadParameter, typer.Abort, typer.Exit — but not the general-purpose ClickException / UsageError. That leaves no public way to raise a concise user-facing CLI error without importing from the private typer._click module (which the 0.26.0 vendoring guidance tells users not to do).

Change

Re-export the two vendored base errors alongside the existing ones, keeping the imports alphabetically ordered:

from ._click.exceptions import ClickException as ClickException
from ._click.exceptions import UsageError as UsageError

Apps can now do:

raise typer.ClickException("something broke")   # exit code 1, Typer-rendered
raise typer.UsageError("bad usage")             # exit code 2

Tests

Added test_click_exception and test_usage_error to tests/test_exit_errors.py asserting the exit codes (1 and 2) and that the message reaches the output.

Verified locally: pytest tests/test_exit_errors.py → 6 passed; ruff check clean.