-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
1d67834
to
d5519fc
Compare
This is a UX improvement PR. Do you guys think there is a better way of doing it? |
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.
hey, sorry for the delay -- made some suggestions for how to generalize this improvement a bit more -- thanks a ton for putting in the effort on this as it's really a big help and not likely something we will ever do otherwise
pipenv/core.py
Outdated
for partition in (part | ||
for e, part in known_exceptions.items() if e in c.err): | ||
known_exceptions_partition = c.err.rpartition(partition) | ||
c.err = "{} {}".format(known_exceptions_partition[1], known_exceptions_partition[2]) |
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.
Won't known_exceptions_partition[1]
and known_exceptions_partition[2]
just be PermissionError: <message>
in this case? I like where this is headed but I feel like it might belong in exceptions.py
. Also note that it really isn't appropriate to manipulate c.err
-- it is the stored stderr
stream output from a subprocess that has already or is currently executing. We really should only ever manipulate how we interpret and display the result.
Possibly we should have some helper method like this:
KNOWN_EXCEPTIONS = {
"PermissionError": "Permission denied:"
}
def prettify_exc(exc):
matched_exceptions = [k for k in KNOWN_EXCEPTIONS.keys() if k in exc]
errors = []
for match in matched_exceptions:
exc, exc_name, error = exc.rpartition(KNOWN_EXCEPTIONS[match])
errors.append("{0} {1}".format(exc_name, crayons.red(decode_for_output(error))))
else:
errors.append("{0}".format(decode_for_output(exc)))
return "\n".join(errors)
And then the exceptions themselves can share a dictionary of known exceptions and use prettify_exc
when environments.is_verbose() is False
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.
That's a good idea. I have pushed the prettify_exc
implementation.
ae8ad82
to
62d3ac4
Compare
Sorry for being incredibly slow on this, but this is looking pretty good to me... I am excited to get things refactored in this direction. Thanks for taking care of this! |
62d3ac4
to
f02676c
Compare
@techalchemy, Awesome. Rebased to |
f02676c
to
cd98e13
Compare
catch known errors in stderr and display them correctly
cd98e13
to
2d75f1a
Compare
Thank you for contributing to Pipenv!
The issue
#2553
The fix
Conservative checks of known exceptions when subprocess returns output.
The checklist
news/
directory to describe this fix with the extension.bugfix
,.feature
,.behavior
,.doc
..vendor
. or.trivial
(this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.