Skip to content
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

feat: ✨ add check error matcher #972

Open
wants to merge 4 commits into
base: feat/sprout-checks-7-check-properties
Choose a base branch
from

Conversation

martonvago
Copy link
Contributor

@martonvago martonvago commented Jan 16, 2025

Description

This PR adds a CheckErrorMatcher object. This is/will be used to filter out unwanted errors easily.
Example usage:

errors = exclude_errors(
        errors,
        [
            CheckErrorMatcher(validator="required", json_path="data"),
            CheckErrorMatcher(validator="type", json_path="path", message="not of type 'array'"),
        ],
    )

I'm going to use this to replace the check_required flag in Sprout's check functions.

Closes #

This PR needs an in-depth review.

Checklist

  • Added or updated tests
  • Updated documentation
  • Ran just run-all

@martonvago martonvago self-assigned this Jan 16, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a very simple class for encapsulating matching logic. The motivation behind this is that filtering CheckErrors or deciding if a CheckError fulfills any of a set of conditions comes up pretty often.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put this class and exclude_errors.py into checks because they are generally applicable, but we can move them to sprout_checks if we think they should be restricted to Sprout.

@martonvago martonvago marked this pull request as ready for review January 16, 2025 16:11
@martonvago martonvago requested a review from a team as a code owner January 16, 2025 16:11
def json_path_matches(self, error: CheckError) -> bool:
"""Determines if this matcher matches the `json_path` of the given `CheckError`.

Matching on the full `json_path` and matching on the field name are supported.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can obviously be refined further (e.g. to allow matching fields with a specific name on resources only), but we can add that as/if we need it. Same goes for message_matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

1 participant