fix(run): a blank script crashes pdm run --list - #3842
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Good call, done. A blank script now shows The test asserts the marker rather than the empty string, so removing the branch fails it with the original |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3842 +/- ##
=======================================
Coverage 88.36% 88.36%
=======================================
Files 121 121
Lines 13240 13250 +10
Branches 2249 2252 +3
=======================================
+ Hits 11700 11709 +9
+ Misses 970 969 -1
- Partials 570 572 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
frostming
left a comment
There was a problem hiding this comment.
Review: APPROVE ✅
The fix is correct, minimal, and safe to merge.
Bug
A blank/whitespace-only script (e.g. blank = " ") made pdm run --list and pdm run --json crash with IndexError: list index out of range — short_description filters blank lines, leaving lines[0] unguarded.
Fix
In Task.short_description (src/pdm/cli/commands/run.py), add a guard:
if not lines:
fallback = "<BLANK_SCRIPT>"
else:
fallback = ...Single change fixes both --list and --json since both call short_description.
Verification (local)
tests/cli/test_run.py: 92 passed (checked out PR head0d8831d2in a worktree)- E2E:
pdm run --listrenders<BLANK_SCRIPT>for both" "and""scripts; non-blank scripts unaffected --jsonemits"help": "<BLANK_SCRIPT>"- Multi-line scripts still get the ellipsis (
…) suffix
CI
All green: Pack + Testing matrix (3.10–3.15 × macOS/ubuntu/windows). mergeStateStatus: CLEAN, mergeable. Codecov: all modified lines covered, coverage unchanged.
Note
The reviewer suggestion (frostming) to mark it with <BLANK_SCRIPT> rather than an empty cell is implemented in the head commit, and the news fragment was updated accordingly.
Pull Request Checklist
news/describing what is new. (news/3842.bugfix.md; happy to renumber it if you would rather it carried a different number)test_run_show_list_of_scripts_with_blank_scriptintests/cli/test_run.py)Describe what you have changed in this PR.
What's broken
A blank script makes
pdm run --listunusable.pdm run --jsonfails the same way. Everything else keeps working, includingpdm run build, so a single blank entry takes out the listing for every other script in the file.The fix
linesis built by filtering blank lines out, so a whitespace-only script leaves it empty, and theelsebranch indexeslines[0]unconditionally.The empty case now falls back to an empty description, which is what the listing needs: a row with a blank Description cell rather than no table at all.
short_descriptionis the only accessor, and its three call sites areshow_listfor the table,as_jsonfor--json, and the task display, so the one guard covers all three.--jsonnow emits"help": ""for the blank script.Scope
There is a second
IndexErrorof the same family further down the file, on the composite path, reachable when{args}interpolates to nothing. That is a separate concern with a behaviour decision attached, so it is not in this PR.Verification
test_run_show_list_of_scripts_with_blank_script, right aftertest_run_show_list_of_scripts, matching its style of asserting on rendered table rows. With the guard reverted it fails with theIndexErrorabove.tests/cli/test_run.py -k "composite or list_of_scripts"is 26 passed, against 25 on main. ruff check and ruff format are both clean.No matching open issue was filed for this, I hit it with a whitespace-only script in my own
pyproject.toml.Disclosure: written with AI assistance (Claude Code). I reproduced the issue, ran the change and the verification myself.