From cbded7d8ca8a3d82c6d2ab47a0c76103a74d8ebe Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Tue, 28 May 2024 18:03:08 +0900 Subject: [PATCH 1/5] Add try-catch exception on venv_resolve_deps --- pipenv/routines/lock.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pipenv/routines/lock.py b/pipenv/routines/lock.py index d49d36df3a..9cf64a645b 100644 --- a/pipenv/routines/lock.py +++ b/pipenv/routines/lock.py @@ -1,4 +1,5 @@ import contextlib +import sys from pipenv.utils.dependencies import ( get_pipfile_category_using_lockfile_section, @@ -61,20 +62,24 @@ 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, - ) + 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, + ) + + except Exception: + sys.exit(1) # Overwrite any category packages with default packages. for category in lockfile_categories: From 87efa84f8b25b2dcbf7cc0a043bc8a4984375092 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Tue, 28 May 2024 18:03:43 +0900 Subject: [PATCH 2/5] Add rich console to log traceback --- pipenv/routines/lock.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pipenv/routines/lock.py b/pipenv/routines/lock.py index 9cf64a645b..199262943e 100644 --- a/pipenv/routines/lock.py +++ b/pipenv/routines/lock.py @@ -1,11 +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, @@ -79,6 +84,7 @@ def do_lock( ) except Exception: + err.print(traceback.format_exc()) sys.exit(1) # Overwrite any category packages with default packages. From 43c69c48a0bdb537f3268243a3ddc4854edbb135 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Tue, 28 May 2024 18:04:18 +0900 Subject: [PATCH 3/5] Remove traceback on RuntimeError --- pipenv/routines/lock.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pipenv/routines/lock.py b/pipenv/routines/lock.py index 199262943e..2fb18af441 100644 --- a/pipenv/routines/lock.py +++ b/pipenv/routines/lock.py @@ -82,6 +82,8 @@ def do_lock( lockfile=lockfile, old_lock_data=old_lock_data, ) + except RuntimeError: + sys.exit(1) except Exception: err.print(traceback.format_exc()) From 2da95d6fb6a807b7428002219b60bf37ddcf3360 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Tue, 28 May 2024 18:15:08 +0900 Subject: [PATCH 4/5] Add news fragment --- news/6166.feature.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 news/6166.feature.rst diff --git a/news/6166.feature.rst b/news/6166.feature.rst new file mode 100644 index 0000000000..389326acc0 --- /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. From 5520374adcabffe11e36fca135fdb96d9a5efc00 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Wed, 29 May 2024 10:41:56 +0900 Subject: [PATCH 5/5] Fix linting error --- news/6166.feature.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/news/6166.feature.rst b/news/6166.feature.rst index 389326acc0..ec0d6bc7be 100644 --- a/news/6166.feature.rst +++ b/news/6166.feature.rst @@ -1,3 +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. +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.