python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.08k stars 2.26k forks source link

Add more context to Poetry error messages #5885

Open MSLeiter opened 2 years ago

MSLeiter commented 2 years ago

Feature Request

I'm using Poetry 1.1.13.

I've recently gotten some Poetry errors for the first time. When Poetry works, it just works and it's great, but when Poetry has an issue it does not provide any context - at least with the 2 errors I've seen so far. This makes it difficult to understand what the issue is and how to even find the general thing that is causing the issue.

For example, I was getting a "ValueError - not enough values to unpack (expected 2, got 1)" for a script entry that was not complete in pyproject.toml, but Poetry only gives the quoted error statement, without mentioning that it was trying to parse the [tool.poetry.scripts] section of pyproject.toml, or that this was during pyproject.toml parsing at all. Preferrably it would also give the line number where the error occurred.

The other error was attempting to parse a non-semver version that was installed to the venv - again, no context to understand what Poetry was trying to do at the time. Thankfully I had just installed that alternate package, and the version name itself was clear, but I didn't know Poetry could fail just parsing the version of an item that was installed to the venv, that Poetry didn't install itself or was mentioned in pyproject.toml at all as a dependency (I hadn't done anything with it yet), so it was originally quiet stunning to get a message that Poetry could not parse a version when I hadn't changed my pyproject.toml at all.

Request:

Please add more context to the error messages, where possible. We need to at least know what Poetry was doing generally, or what line of which file it was parsing, etc. to be able to decipher what is going on.

Some possibilities:

  1. If there is a parse error, print the filename and line number (if line number is possible), or print the text that was attempting to be parsed (i.e. perhaps the raw line of text prior to parsing). With the raw text, we can search our files to find the problem location.
  2. Currently the errors only show the final piece of the exception call stack - maybe Poetry should print the entire call stack? I realize often the additional steps are not needed and take up a lot of space in the shell, but sometimes they are required to understand what went wrong.
Secrus commented 2 years ago

a lot was improved in the incoming 1.2 release. You can check it out from master branch

dimbleby commented 1 year ago

When hitting an exception the stack is available by running with -vv.

You didn't say how to reproduce either of the errors that you're complaining about.

4597 shows the way: reports for specific errors are useful and actionable, and if you can do that for your ValueError then please do. (Even more useful is a pull request improving those particular errors).

But as a catch-all "please be better" - I suggest this can only be closed.

sersorrel commented 1 year ago

If your pyproject.toml includes something like this:

[tool.poetry.scripts]
foo = "foo.main"

then you get this behaviour:

$ poetry install
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: foo (0.1.0)
not enough values to unpack (expected 2, got 1)

Using -v at least gives me an indication that the problem might have something to do with console_scripts (-vv gives a full stack trace, which is not actually really helpful here):

$ poetry -v install
Using virtualenv: /home/ash/src/foo/.venv
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 0 installs, 0 updates, 0 removals, 10 skipped

  • Installing aiohttp (3.8.3): Skipped for the following reason: Already installed
  • Installing aiosignal (1.3.1): Skipped for the following reason: Already installed
  • Installing attrs (22.2.0): Skipped for the following reason: Already installed
  • Installing discord-py (2.1.0): Skipped for the following reason: Already installed
  • Installing async-timeout (4.0.2): Skipped for the following reason: Already installed
  • Installing multidict (6.0.4): Skipped for the following reason: Already installed
  • Installing yarl (1.8.2): Skipped for the following reason: Already installed
  • Installing charset-normalizer (2.1.1): Skipped for the following reason: Already installed
  • Installing idna (3.4): Skipped for the following reason: Already installed
  • Installing frozenlist (1.3.3): Skipped for the following reason: Already installed

Installing the current project: foo (0.1.0)
  ValueError

  not enough values to unpack (expected 2, got 1)

  at /nix/store/ipjcly953nwlisk5gvay1895zs95k5a2-python3.10-poetry-1.3.0/lib/python3.10/site-packages/poetry/masonry/builders/editable.py:177 in _add_scripts
      173│
      174│         scripts = entry_points.get("console_scripts", [])
      175│         for script in scripts:
      176│             name, script = script.split(" = ")
    → 177│             module, callable_ = script.split(":")
      178│             callable_holder = callable_.split(".", 1)[0]
      179│
      180│             script_file = scripts_path.joinpath(name)
      181│             self._debug(

but I feel like – when the issue is "I typed a . when I should have typed a :" – there should be enough context given in the printed-by-default error messages alone to diagnose the issue without inspecting the Poetry source code.

KotlinIsland commented 8 months ago

What I would like to see is an explainer for an unhandled exception along the lines of:

Desired:

> poetry install

An unexpected error occurred during execution of poetry:

    TOMLDecodeError: Cannot overwrite a value (at line 10, column 20)

You can run again with `--verbose` and raise an issue at https://github.com/python-poetry/poetry/issues