diff --git a/news/6166.feature.rst b/news/6166.feature.rst new file mode 100644 index 0000000000..ec0d6bc7be --- /dev/null +++ b/news/6166.feature.rst @@ -0,0 +1,3 @@ +This is an enhancement of error message regards to https://github.com/pypa/pipenv/issues/6073. +Inside ``do_lock`` method, exceptions in ``venv_resolve_deps`` wasn't properly handled by far. This PR handles exception to improve this problem. +Since RuntimeError raised inside ``venv_resolve_deps`` can't be easily modified, (it's related to so many components) it raises sys.exit(1) when RuntimeError occurs, and additional traceback log is added on general Exception. diff --git a/pipenv/routines/lock.py b/pipenv/routines/lock.py index 78893b3077..6ab310760c 100644 --- a/pipenv/routines/lock.py +++ b/pipenv/routines/lock.py @@ -1,10 +1,16 @@ import contextlib +import sys +import traceback +from pipenv.patched.pip._vendor import rich from pipenv.utils.dependencies import ( get_pipfile_category_using_lockfile_section, ) from pipenv.vendor import click +console = rich.console.Console() +err = rich.console.Console(stderr=True) + def do_lock( project, @@ -62,21 +68,28 @@ def do_lock( from pipenv.utils.resolver import venv_resolve_deps - # Mutates the lockfile - venv_resolve_deps( - packages, - which=project._which, - project=project, - category=pipfile_category, - clear=clear, - pre=pre, - allow_global=system, - pypi_mirror=pypi_mirror, - pipfile=packages, - lockfile=lockfile, - old_lock_data=old_lock_data, - extra_pip_args=extra_pip_args, - ) + try: + # Mutates the lockfile + venv_resolve_deps( + packages, + which=project._which, + project=project, + category=pipfile_category, + clear=clear, + pre=pre, + allow_global=system, + pypi_mirror=pypi_mirror, + pipfile=packages, + lockfile=lockfile, + old_lock_data=old_lock_data, + extra_pip_args=extra_pip_args, + ) + except RuntimeError: + sys.exit(1) + + except Exception: + err.print(traceback.format_exc()) + sys.exit(1) # Overwrite any category packages with default packages. for category in lockfile_categories: