Skip to content

Commit f9feb00

Browse files
authored
Merge pull request #6338 from pypa/better-error-messaeg-on-resolution-failure-6336
fix: when a resolution is failed show a helpful error
2 parents 94c9658 + b4d5d1f commit f9feb00

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

pipenv/exceptions.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def show(self, file=None):
7979
if isinstance(self.extra, str):
8080
self.extra = [self.extra]
8181
for extra in self.extra:
82-
extra = f"[pipenv.exceptions.{self.__class__.__name__}]: {extra}"
8382
console.print(extra)
8483
console.print(f"{self.message}")
8584

@@ -310,29 +309,16 @@ def __init__(self, message):
310309
class ResolutionFailure(PipenvException):
311310
def __init__(self, message, no_version_found=False):
312311
extra = (
313-
"{}: Your dependencies could not be resolved. You likely have a "
314-
"mismatch in your sub-dependencies.\n "
315-
"You can use {} to bypass this mechanism, then run "
316-
"{} to inspect the versions actually installed in the virtualenv.\n "
317-
"Hint: try {} if it is a pre-release dependency."
318-
"".format(
319-
click.style("Warning", fg="red", bold=True),
320-
click.style("$ pipenv run pip install <requirement_name>", fg="yellow"),
321-
click.style("$ pipenv graph", fg="yellow"),
322-
click.style("$ pipenv lock --pre", fg="yellow"),
323-
),
312+
"Your dependencies could not be resolved. You likely have a "
313+
"mismatch in your sub-dependencies.\n"
314+
"You can use [yellow]$ pipenv run pip install <requirement_name>[/yellow] to bypass this mechanism, then run "
315+
"[yellow]$ pipenv graph[/yellow] to inspect the versions actually installed in the virtualenv.\n"
316+
"Hint: try [yellow]$ pipenv lock --pre[/yellow] if it is a pre-release dependency."
324317
)
325-
if "no version found at all" in message:
326-
no_version_found = True
327-
message = click.style(f"{message}", fg="yellow")
328-
if no_version_found:
329-
message = "{}\n{}".format(
330-
message,
331-
click.style(
332-
"Please check your version specifier and version number. "
333-
"See PEP440 for more information.",
334-
fg="cyan",
335-
),
318+
if "no version found at all" in str(message):
319+
message += (
320+
"[cyan]Please check your version specifier and version number. "
321+
"See PEP440 for more information.[/cyan]"
336322
)
337323
PipenvException.__init__(self, message, extra=extra)
338324

pipenv/utils/resolver.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,9 @@ def resolve(cmd, st, project):
765765
out = c.stdout.read()
766766
if returncode != 0:
767767
st.console.print(environments.PIPENV_SPINNER_FAIL_TEXT.format("Locking Failed!"))
768-
# err.print(out.strip())
769768
if not is_verbose:
770769
err.print(errors)
771-
raise RuntimeError("Failed to lock Pipfile.lock!")
770+
raise ResolutionFailure("Failed to lock Pipfile.lock!")
772771
if is_verbose:
773772
err.print(out.strip())
774773
return subprocess.CompletedProcess(c.args, returncode, out, errors)

0 commit comments

Comments
 (0)