python-poetry / python-poetry/poetry

Incomplete error message in exception

Open
#5,598 2 comments 0 reactions 1 assignee View on GitHub

@vighnesh-kadam is already working on this.

Since May 22, 2022.

area/error-handling
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: MacOS 12.3.1
  • Poetry version: 1.1.13
  • Link of a Gist with the contents of your pyproject.toml file: I can't share it (at least the part with the bug).

Issue

When catching exception, poetry does not give any useful information as it discards the original error message. As an example, poetry can't access the keyring on my mac, but it it doesn't tell me why, just:

  KeyRingError

  Unable to retrieve the password for poetry-repository-iktos from the key ring

  at ~/.poetry/lib/poetry/utils/password_manager.py:40 in get_password
       36│         try:
       37│             return keyring.get_password(name, username)
       38│         except (RuntimeError, keyring.errors.KeyringError):
       39│             raise KeyRingError(
    →  40│                 "Unable to retrieve the password for {} from the key ring".format(name)
       41│             )
       42│
       43│     def set_password(self, name, username, password):
       44│         if not self.is_available():

without useful information in debug mode. If the message from the original exception was also printed, the errors would more useful.
It could be done using the raise ... from ... syntax, for example:

try:
    return keyring.get_password(name, username)
except (RuntimeError, keyring.errors.KeyringError) as err:
    raise KeyRingError(
        "Unable to retrieve the password for {} from the key ring".format(name)
    ) from err

or by including the original error message, when available, to the new exception message.

In my case, the original error message (the one from keyring.errors.KeyringError) would tell me that Apple does not like my python interpreter because it is not codesign...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.