Skip to content

Commit

Permalink
Add error message for invalid concurrency value
Browse files Browse the repository at this point in the history
This commit adds a detailed error message when a user passes in a
concurrency outside the expected range (which is >= 0). Previously
we'd raise an unhandled IndexError because of going outside the list
bounds deeper in the code, which wasn't super useful or informative for
users. This fixes that by detecting when we have an invalid input up
front and print that out before we run anything.

Related to: #202
  • Loading branch information
mtreinish committed Feb 20, 2019
1 parent bf80536 commit e1c4b0b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stestr/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def take_action(self, parsed_args):
color = args.color
abbreviate = args.abbreviate
suppress_attachments = args.suppress_attachments
if concurrency and concurrency < 0:
msg = ("The provided concurrency value: %s is not valid. An "
"integer >= 0 must be used.\n" % concurrency)
stdout.write(msg)
return 2
verbose_level = self.app.options.verbose_level
stdout = open(os.devnull, 'w') if verbose_level == 0 else sys.stdout
result = run_command(
Expand Down Expand Up @@ -308,6 +313,11 @@ def run_command(config='.stestr.conf', repo_type='file',
exit(1)
repo = util.get_repo_initialise(repo_type, repo_url)
combine_id = None
if concurrency and concurrency < 0:
msg = ("The provided concurrency value: %s is not valid. An integer "
">= 0 must be used.\n" % concurrency)
stdout.write(msg)
return 2
if combine:
latest_id = repo.latest_id()
combine_id = six.text_type(latest_id)
Expand Down

0 comments on commit e1c4b0b

Please sign in to comment.