Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Handle incorrect argument, print output file locations #149

Merged
merged 4 commits into from
Feb 27, 2018

Conversation

honzajavorek
Copy link
Contributor

Introducing following changes:

  • bb dep check non-existing-package doesn't crash anymore
  • bb dep check package@non-existing-version doesn't crash anymore
  • The bb dep check command prints out locations where the output files are saved

Before:

$ bb dep check chromedriver
Analyzing the package...
Getting dependencies...
Creating the list of 4th party deps...
Creating the Public License field contents...

After:

$ bb dep check chromedriver
Analyzing the package...
Getting dependencies...
Creating the list of 4th party deps... /Users/honza/Projects/black-belt/list.txt
Creating the Public License field contents... /Users/honza/Projects/black-belt/licenses.txt

abtris
abtris previously approved these changes Jan 24, 2018
Copy link
Contributor

@abtris abtris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@abtris
Copy link
Contributor

abtris commented Jan 24, 2018

Need rebase with master

Almad
Almad previously requested changes Jan 24, 2018
Copy link
Contributor

@Almad Almad left a 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.

dep_version = run(['npm', 'view', dep_name, 'version'])
try:
dep_version = run(['npm', 'view', dep_name, 'version'])
except subprocess.CalledProcessError:
Copy link
Contributor

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).

Copy link
Member

@kylef kylef Jan 24, 2018

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'

https://api-docs.npms.io

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Almad Yup, my solution is a hotfix.
@kylef That's an amazing finding/an idea. I support you mentally in sending a PR! 😏

try:
install(dep_name, dep_version, tmp_dir, dev=dev)
except subprocess.CalledProcessError:
raise click.BadParameter('The npm package could not be installed')
Copy link
Contributor

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)

Copy link
Contributor Author

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.

@honzajavorek
Copy link
Contributor Author

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.

@honzajavorek honzajavorek force-pushed the honzajavorek/print-output-file-locations branch from 33fa172 to 96ca12c Compare January 29, 2018 09:42
@honzajavorek
Copy link
Contributor Author

@kylef @Almad Updated

@abtris
Copy link
Contributor

abtris commented Feb 19, 2018

@Almad can you make re-review we have 21 days old last comment

kylef
kylef previously approved these changes Feb 19, 2018
else:
if ctx.params.get('debug'):
raise
raise click.BadParameter('Unable to figure out the package version')
Copy link
Member

@kylef kylef Feb 19, 2018

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.

Copy link
Contributor Author

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

@honzajavorek
Copy link
Contributor Author

@kylef I somehow managed to dismiss your review 😞

@abtris abtris merged commit 1aad65f into master Feb 27, 2018
@abtris abtris deleted the honzajavorek/print-output-file-locations branch February 27, 2018 10:41
Copy link
Contributor

@Almad Almad left a 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')
Copy link
Contributor

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')
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants