-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic exceptions vs Specific exceptions #1784
Comments
I believe no-one is ever going to handle a URLParsingError so there should be no need for it. If that statement turns out wrong and a need arises later, adding a derived error is easy. The commit is good. |
Updater does use some of the specific exceptions. I would not object to TrustedMetadataSet having better exception documentation, the reason it doesn't is probably the fact that it's currently private (documenting too much does lead to outdated documentation...) For updater itself I think documenting just RepositoryError (and not the more specific ones) is reasonable: Updater users are not going to care about the details. |
I just did a thorough review of all exceptions we raise in api and ngclient and it all looks good modulo some missing documentation (will post related comments to #1785, where they seem more appropriate). So I agree with what Jussi says about python-tuf/tuf/ngclient/_internal/trusted_metadata_set.py Lines 62 to 65 in cb7bd6a
Let's do that and close this issue? |
Yes: PR #1805 |
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
andLengthOrHashMismatchError
which derive fromRepositoryError
.Still, there are two use cases that are worth discussing:
TrustedMetadataSet
where in one API call we are throwing generic and specific exceptions.That's happening inside each of the functions
update*
insideTrustedMetadataSet
we throwRepositoryError
,ReplayedMetadataError
,ExpiredMetadataError
andUnsignedMetadataError
(fromverify_delegate()
) at the same time.One idea could be to define new specific exceptions (which derive from
RepositoryError
and replace the instances ofRepositoryError
with them.Read and synchronize with issues:
TrustedMetadataSet
update*
function docstrings we only document that we are throwingRepositoryError
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).
_get_session
in moduletuf/ngclient/_internal/request_fetcher.py
we currently throwURLParsingError
:python-tuf/tuf/ngclient/_internal/requests_fetcher.py
Line 135 in 0e26364
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 fromDownloadError
?Does my change in this commit make sense?
The text was updated successfully, but these errors were encountered: