Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conservative check for known exceptions in subprocess stderr. #3463

Merged
merged 3 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2553.behavior.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make conservative checks of known exceptions when subprocess returns output, so user won't see the whole traceback - just the error.
5 changes: 3 additions & 2 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,10 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
)
click.echo(crayons.blue("{0}".format(c.out)), err=True)
if c.returncode != 0:
sp.fail(environments.PIPENV_SPINNER_FAIL_TEXT.format(u"Failed creating virtual environment"))
sp.fail(environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed creating virtual environment"))
error = c.err if environments.is_verbose() else exceptions.prettify_exc(c.err)
raise exceptions.VirtualenvCreationException(
extra=[crayons.blue("{0}".format(c.err)),]
extra=[crayons.red("{0}".format(error)),]
)
else:

Expand Down
19 changes: 19 additions & 0 deletions pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
)
from .vendor.click.types import Path
from .vendor.click.utils import echo as click_echo
import vistir

KNOWN_EXCEPTIONS = {
"PermissionError": "Permission denied:",
}

def handle_exception(exc_type, exception, traceback, hook=sys.excepthook):
if environments.is_verbose() or not issubclass(exc_type, ClickException):
Expand Down Expand Up @@ -402,3 +406,18 @@ def __init__(self, req=None):
)
extra = [crayons.normal(decode_for_output(str(req)))]
super(RequirementError, self).__init__(message, extra=extra)
super(ResolutionFailure, self).__init__(fix_utf8(message), extra=extra)


def prettify_exc(error):
"""Catch known errors and prettify them instead of showing the
entire traceback, for better UX"""
matched_exceptions = [k for k in KNOWN_EXCEPTIONS.keys() if k in error]
if not matched_exceptions:
return "{}".format(vistir.misc.decode_for_output(error))
errors = []
for match in matched_exceptions:
_, error, info = error.rpartition(KNOWN_EXCEPTIONS[match])
errors.append("{} {}".format(error, info))

return "\n".join(errors)