Repository navigation
Closed
Description
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:
- There are multiple places inside
TrustedMetadataSetwhere in one API call we are throwing generic and specific exceptions.
That's happening inside each of the functionsupdate*insideTrustedMetadataSetwe throwRepositoryError,ReplayedMetadataError,ExpiredMetadataErrorandUnsignedMetadataError(fromverify_delegate()) at the same time.
One idea could be to define new specific exceptions (which derive fromRepositoryErrorand replace the instances ofRepositoryErrorwith them.
Read and synchronize with issues:
- Do we need a new MissingInformationError/MissingMetadataError? #1778
- Do we need a new (Metadata)TypeError? #1779
- ngclient: decide what to do with requests (Fetcher impl) errors #1714
- review/document client exceptions #1312
- Inside the
TrustedMetadataSetupdate*function docstrings we only document that we are throwingRepositoryErrorwithout 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).
- Inside
_get_sessionin moduletuf/ngclient/_internal/request_fetcher.pywe currently throwURLParsingError:raise exceptions.URLParsingError(
In my commit e8f26eb inside pr Add new exceptions file for exceptions in the new code #1725 I am replacing it withDownloadError.
The question is do we want to keep the specific exception -URLParsingErrorand make it derive fromDownloadError?
Does my change in this commit make sense?
Reacted by Lukas Pühringer
Reacted by Lukas Pühringer
Metadata
Metadata
Assignees
Labels
1.0.0 blockersTo be addressed before 1.0.0 release
Activity
jku commentedon Jan 20, 2022
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.
jku commentedon Jan 20, 2022
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.
lukpueh commentedon Jan 27, 2022
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
TrustedMetadataSetexceptions and I suggest we remove the following TODO comment?python-tuf/tuf/ngclient/_internal/trusted_metadata_set.py
Lines 62 to 65 in cb7bd6a
Let's do that and close this issue?
jku commentedon Jan 28, 2022
Yes: PR #1805