-
Notifications
You must be signed in to change notification settings - Fork 1
Handle incorrect argument, print output file locations #149
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Need rebase with master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd either make less granular exception checking or print stderr in error messages, otherwise this will make very confusing error outputs.
blackbelt/commands/dep.py
Outdated
dep_version = run(['npm', 'view', dep_name, 'version']) | ||
try: | ||
dep_version = run(['npm', 'view', dep_name, 'version']) | ||
except subprocess.CalledProcessError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to look into exit codes / status messages, because this wraps multiple errors under one hood and can make it very tricky to debug (i.e. if there is any other general npm or network problem).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be simpler to use the NPM web API directly, instead of invoking the CLI tool and trying to interpret it and it's response.
Can simply do a GET request to get the package information https://api.npms.io/v2/package/dredd
and look for version in there. 404
response would indicate missing package.
Python one liner, can be broken into more for a response.raise_for_status()
:
>>> requests.get('https://api.npms.io/v2/package/dredd').json()['collected']['metadata']['version']
'4.9.3'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blackbelt/dependencies.py
Outdated
try: | ||
install(dep_name, dep_version, tmp_dir, dev=dev) | ||
except subprocess.CalledProcessError: | ||
raise click.BadParameter('The npm package could not be installed') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, in this case, I'd do ...installed: ', stderr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, passing the error through might be worth.
Not sure when I'll be able to get back to this tho. Feel free to jump in and cherry-pick or to bother me to finalize this. It has zero priority for me right now. |
33fa172
to
96ca12c
Compare
@Almad can you make re-review we have 21 days old last comment |
blackbelt/commands/dep.py
Outdated
else: | ||
if ctx.params.get('debug'): | ||
raise | ||
raise click.BadParameter('Unable to figure out the package version') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is semantically correct, the error is not a "BadParameter" but some HTTP/DNS or similar problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it to click.Abort
@kylef I somehow managed to dismiss your review 😞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add more into the message for diagnosis
except Exception as e: | ||
if debug: | ||
raise | ||
raise click.BadParameter('The npm package could not be installed') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abtris wouldn't it make sense to include the e.message
?
else: | ||
if ctx.params.get('debug'): | ||
raise | ||
raise click.Abort('Unable to figure out the package version') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say "why"—at least a status_code or pick something sensible from the response
Introducing following changes:
bb dep check non-existing-package
doesn't crash anymorebb dep check package@non-existing-version
doesn't crash anymorebb dep check
command prints out locations where the output files are savedBefore:
After: