Skip to content

Conversation

@tmathern
Copy link
Collaborator

@tmathern tmathern commented Jan 7, 2026

Changes in this pull request

  • Fixes exception hierarchies to be able to leverage typed exceptions better
  • Still keeps backwards compatibility with previous exception handling

Checklist

  • This PR represents a single feature, fix, or change.
  • All applicable changes have been documented.
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

@tmathern tmathern self-assigned this Jan 7, 2026

class C2paError(Exception):
"""Exception raised for C2PA errors."""
"""Exception raised for C2PA errors.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing error class hierarchy to leverage typed errors better, especially in the new Reader factory method

self.message = message
super().__init__(message)

class Assertion(Exception):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specific exceptions (all the types nested in the parent class) got un-nested from here so they can inherit from the base C2pa exception and get the C2paException type.

# Attach exception subclasses to C2paError for backward compatibility
# Preserves behavior for exception catching like except C2paError.ManifestNotFound,
# also reduces imports (think of it as an alias of sorts)
C2paError.Assertion = _C2paAssertion
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An we still can use the parent type for general error catching!

if ': ' in error_str:
parts = error_str.split(': ', 1)
else:
parts = error_str.split(' ', 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the c api is inconsistent here, we should add an issue to fix it so that we always use the colon

@tmathern tmathern merged commit f187bee into vNext Jan 7, 2026
38 of 39 checks passed
@tmathern tmathern deleted the mathern/exceptions-refactor branch January 7, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants