Skip to content

Commit

Permalink
Check gh-issue- is int before checking range for better error
Browse files Browse the repository at this point in the history
Invalid GitHub issue number! ('one-two')

instead of:

ValueError: invalid literal for int() with base 10: 'one-two'
  • Loading branch information
hugovk committed Nov 9, 2024
1 parent 4cb4857 commit 8e590fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/blurb/blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ def finish_entry():
# we'll complain about the *first* error
# we see in the blurb file, which is a
# better user experience.
if key == "gh-issue" and int(value) < lowest_possible_gh_issue_number:
throw(f"The gh-issue number must be {lowest_possible_gh_issue_number} or above, not a PR number.")

if key in issue_keys:
try:
int(value)
except (TypeError, ValueError):
throw(f"Invalid {issue_keys[key]} issue number! ({value!r})")

if key == "gh-issue" and int(value) < lowest_possible_gh_issue_number:
throw(f"The gh-issue number must be {lowest_possible_gh_issue_number} or above, not a PR number.")

if key == "section":
if no_changes:
continue
Expand Down
4 changes: 4 additions & 0 deletions tests/test_blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ def test_parse():
"..bpo: one-two\n..section: IDLE\nHello world!",
r"Invalid bpo issue number! \('one-two'\)",
),
(
"..gh-issue: one-two\n..section: IDLE\nHello world!",
r"Invalid GitHub issue number! \('one-two'\)",
),
(
"..gh-issue: 123456\n..section: Funky Kong\nHello world!",
r"Invalid section 'Funky Kong'! You must use one of the predefined sections",
Expand Down

0 comments on commit 8e590fc

Please sign in to comment.