Long tasks name make `invoke --list | grep a` crash with "invalid width"

Open Beginner friendly
#1,071 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
cli

Research direction

Start in invoke/program.py at list_tasks, list_flat, display_with_columns, and print_columns, following the traceback from invoke --list | grep a. Reproduce the long task name case and inspect how the available terminal width reaches textwrap. Done means the command no longer raises ValueError: invalid width 0 and still displays the task list.

Written by the indexing model from the issue text.

Description

Sample code:

from invoke.tasks import task

@task
def my_very_long_task_name_that_is_completely_legit_but_make_grep_crash_aaaaaa(c):
    print('Here')

Run wihtout grep:

$ uv run invoke --list
Available tasks:

  my-very-long-task-name-that-is-completely-legit-but-make-grep-crash-aaaaaa

Run with grep:

$ uv run invoke --list | grep a
Traceback (most recent call last):
  File "/my/project/.venv/bin/invoke", line 10, in <module>
Available tasks:
    sys.exit(program.run())
             ^^^^^^^^^^^^^
  File "/my/project/.venv/lib/python3.12/site-packages/invoke/program.py", line 391, in run
    self.parse_cleanup()
  File "/my/project/.venv/lib/python3.12/site-packages/invoke/program.py", line 530, in parse_cleanup
    self.list_tasks()
  File "/my/project/.venv/lib/python3.12/site-packages/invoke/program.py", line 815, in list_tasks
    getattr(self, "list_{}".format(self.list_format))()
  File "/my/project/.venv/lib/python3.12/site-packages/invoke/program.py", line 819, in list_flat
    self.display_with_columns(pairs=pairs)
  File "/my/project/.venv/lib/python3.12/site-packages/invoke/program.py", line 932, in display_with_columns
    self.print_columns(pairs)
  File "/my/project/.venv/lib/python3.12/site-packages/invoke/program.py", line 969, in print_columns
    help_chunks = wrapper.wrap(help_str)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/my/project/.share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/textwrap.py", line 360, in wrap
    return self._wrap_chunks(chunks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/my/project/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/textwrap.py", line 254, in _wrap_chunks
    raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width 0 (must be > 0)

System info:

invoke 3.0.3
Python 3.12.11 (on darwin)
Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.