Skip to content

Refactor/normalize exceptions #586

Open
@bhrutledge

Description

@bhrutledge

Looking over the custom exceptions in exceptions.py and searching for how they're used, I see a couple patterns. The first is an empty class, with the message provided at raise. The second is to define a message template in the exception, using arguments provided at raise with .from_args(...).

The empty class pattern is more common, but leads to duplicate, possibly inconsistent, and sometimes long message text in the code. To improve this, I propose:

  • Moving all exception messages to exceptions.py, making them templates where needed. I don't have a specific pattern in mind for this, and would prefer to follow one used by a larger project. This could mean replacing .from_args.

  • Adding subclasses of InvalidDistribution with a more specific message, for example:

    raise exceptions.DistributionFileNotFound(filename)
    raise exceptions.InvalidDistributionFormat(filename)
    
  • Combining UploadToDeprecatedPyPIDetected and InvalidPyPIUploadURL as suggested in Add helpful error message for incorrect PyPI URL #509 (comment)

  • Looking for other opportunities to combine or extract exceptions. For example, could PackageNotFound be the same as DistributionFileNotFound?

  • Looking for opportunities to improve the exception messages. For example, somewhere I heard the concept of "help messages" instead of "error messages".

Happy to do this in multiple PR's.


PS: GitHub's code navigation is really handy. For example, when viewing exceptions.py, click a class name, see where it's referenced, and click one to go there:

Screen Shot 2020-04-15 at 6 38 15 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionDiscussion/decision needed from maintainers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions