-
Notifications
You must be signed in to change notification settings - Fork 278
Metadata API: Avoid raising securesystemslib exceptions #1734
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
Metadata API: Avoid raising securesystemslib exceptions #1734
Conversation
Pull Request Test Coverage Report for Build 1722983367Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
2130319
to
fd541d8
Compare
fd541d8
to
195fb0d
Compare
I think we can remove the last SSLIB error as well #1725 (comment) opinions? |
👍 |
195fb0d
to
9090da2
Compare
9090da2
to
1301807
Compare
I think there's a misunderstanding. My comments on securesystemslib.StorageError vs OSError were made in the context of the client: there a securesystemslib error just makes life harder for no good reason. In Metadata API there was a conscious decision to abstract storage (for the repository use case). Removing StorageError completely makes no sense here: we might want to expose StorageError in our exceptions though so that users don't need to import SSLIB explicitly. I agree about the other SSLIB errors. |
1301807
to
08ba94a
Compare
@jku the pr is updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this. Would appreciate other maintainer opinions (@lukpueh ?) on my suggestion to re-export StorageError: I feel like that's a good strategy but maybe a little unusual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding StorageError
, I think re-exporting makes sense. See inline for more comments...
@@ -305,9 +304,7 @@ def sign( | |||
Raises: | |||
tuf.api.serialization.SerializationError: | |||
'signed' cannot be serialized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not raised anymore. Can you move the serialize call out of the try block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment from above is nonsense. What I wanted to say is, if we except all below when calling sign(serialize...)
and re-raise as UnsignedMetadataError
, then SerializationError
won't be raised anymore.
So either we take the call to serialize out of the try block below or we update the docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to move the serialization outside the try block so that the serialization error will propagate as I don't think it's good to hide it with UnsignedMetadataError
exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow I completely missed this. Good solution I think.
Signed-off-by: Martin Vrachev <[email protected]>
Reexport securesystemslib StorageError, so that our users can catch it without importing securesystemslib. The securesystemslib StorageError makes sense in the context of metadata API, because it supports different storage interfaces and this exception is denoting all possible errors that could arrise from using any kind of storage interface. Additionally, I changed the places where we mention that StorageError is thrown, so that our users will know they can directly import it from tuf/api/exceptions.py instead of importing securesystemslib. Signed-off-by: Martin Vrachev <[email protected]>
Catch Metadata.sign() securesystemslib exceptions and instead throw a more general UnsignedMetadataError exception. We don't want to expose securesystemslib exceptions and it's better to replace them with a more general exception that could be easily handled. As the signer is an argument implementing securesystemslib.signer.Signer interface we don't know what exception will it throw. That's why we need to catch all possible exceptions during signing and raise UnsignedMetadataError. That is the same reason why we should move the serialization outside the "try" block, so a tuf.api.serialization.SerializationError can propagate and warn the user that 'signed' cannot be serialized. Signed-off-by: Martin Vrachev <[email protected]>
Add missing tests testing raising documented exceptions for "Metadata.sign()", "Metadata.to_file()" and "Metadata.from_file()". Signed-off-by: Martin Vrachev <[email protected]>
08ba94a
to
9533c3f
Compare
Fixes #1646
Description of the changes being introduced by the pull request:
In this pr, I aim to remove the need of our users to import securesystemslib
in order to catch the exceptions thrown by
tuf/metadata/api.py
.I either reexport securesystemslib exceptions or
reraise them by using tuf exceptions.
Reexporting securesystemslib exceptions is required so that users
of code that throws these exceptions doesn't have to import
securesystemslib to handle them.
A couple of additional fixes are added to this pr as well.
Signed-off-by: Martin Vrachev [email protected]
Please verify and check that the pull request fulfills the following
requirements: