pallets / pallets/click

Display exception notes when raising `ClickException`

Open
#2,740 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

parsing
Dominant language
Python
Stars
17.7k
Forks
2.3k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

Since 3.11 Python supports adding notes on exceptions. Basically this is completion of the exception message, and it can be useful to add context.

Notes are currently not displayed when ClickException are raised:

import click

@click.command()
def foobar():
    exc = click.ClickException("foo")
    exc.add_note("bar")
    raise exc

if __name__ == '__main__':
    foobar()
$ python foobar.py
Error: foo

I suggest to display the notes in addition to the main message.

What do you think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the foobar.py example from the issue and trace how ClickException is rendered by the CLI. Done means exception notes added with add_note are displayed in addition to the main Error: foo message, with coverage for the demonstrated behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.