Skip to content

Generic exceptions vs Specific exceptions #1784

Closed
@MVrachev

Description

@MVrachev

Description of issue or feature request:
We want to use a shortlist of exceptions that will be thrown from our APIs, so that our users can handle them easily.
On another hand that doesn't stop us from creating other more specific exceptions that derive from those main exceptions.
This allows us to easily test that specific errors were thrown when we expected them.
For example, we are using BadVersionError and LengthOrHashMismatchError which derive from RepositoryError.

Still, there are two use cases that are worth discussing:

  1. There are multiple places inside TrustedMetadataSet where in one API call we are throwing generic and specific exceptions.
    That's happening inside each of the functions update* inside TrustedMetadataSet we throw RepositoryError, ReplayedMetadataError, ExpiredMetadataError and UnsignedMetadataError (from verify_delegate()) at the same time.
    One idea could be to define new specific exceptions (which derive from RepositoryError and replace the instances of RepositoryError with them.

Read and synchronize with issues:

  1. Inside the TrustedMetadataSet update* function docstrings we only document that we are throwing RepositoryError without specifying the specific exceptions. If none of them are documented in the Raises section of the method docstrings (they only mention the broad RepositoryError), do we expect anyone to handle them? If we do, we should probably document them?

Inspired by #1725 (comment).

  1. Inside _get_session in module tuf/ngclient/_internal/request_fetcher.py we currently throw URLParsingError:
    raise exceptions.URLParsingError(

    In my commit e8f26eb inside pr Add new exceptions file for exceptions in the new code #1725 I am replacing it with DownloadError.
    The question is do we want to keep the specific exception - URLParsingError and make it derive from DownloadError?
    Does my change in this commit make sense?

Metadata

Metadata

Assignees

Labels

1.0.0 blockersTo be addressed before 1.0.0 release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions