Skip to content

Exceptions in metadata API, especially verify() #1351

@jku

Description

@jku

I've just tried verifying metadata using the new API. I wanted to do this:

if md.verify(key):
    print("yay")

but it looks like I'll end up with

from securesystemslib import exceptions as sslib_exceptions
from tuf import exceptions
from tuf.api import serialization

try:
    if md.verify(key):
        print("yay")
except (
    exceptions.Error, 
    sslib_exceptions.FormatError,
    serialization.SerializationError, 
    sslib_exceptions.CryptoError,
    sslib_exceptions.UnsupportedAlgorithmError
):
    # 🤷
    pass        

It feels like we could do better.

This issue is about exceptions handling in general but I'm fine if the solutions are case-by-case (like maybe verify specifically just does not need to throw at all).

Some specific issues:

  • It feels like in most cases bleeding these securesystemslib errors through the API is wrong: I don't really want to handle them in my client code and I don't think we should expect client developers to know how to do that
  • why are serialization errors defined in a different place than other errors? should serialization errors at least derive from generic exceptions.Error so I could pass all TUF errors with a single line if I want to (like I think makes sense with verify())

Metadata

Metadata

Assignees

Labels

backlogIssues to address with priority for current development goals

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions