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 CheckErrorMatcher object #972

Merged
merged 90 commits into from
Jan 23, 2025
Merged

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.

This PR needs an in-depth review.

Checklist

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

martonvago and others added 30 commits December 19, 2024 15:03
Co-authored-by: Luke W. Johnston <[email protected]>
Co-authored-by: Signe Kirk Brødbæk <[email protected]>
Co-authored-by: Signe Kirk Brødbæk <[email protected]>
martonvago and others added 18 commits January 20, 2025 15:42
…at/sprout-checks-4-sprout-specific-package-and-resource-errors
…ce-errors' into feat/sprout-checks-5-check-resource-properties
Co-authored-by: Luke W. Johnston <[email protected]>
Co-authored-by: Luke W. Johnston <[email protected]>
Co-authored-by: Luke W. Johnston <[email protected]>
Base automatically changed from feat/sprout-checks-7-check-properties to main January 21, 2025 13:45
@lwjohnst86 lwjohnst86 changed the title feat: ✨ add check error matcher feat: ✨ add CheckErrorMatcher object Jan 22, 2025
lwjohnst86
lwjohnst86 previously approved these changes Jan 22, 2025
Copy link
Member

@lwjohnst86 lwjohnst86 left a comment

Choose a reason for hiding this comment

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

I have a hard time seeing what this does or it's usefulness, but I think it would help once we move these functionality over into a standalone package with some guides showing the functions in action. Or seeing the functions in action in other functions within Sprout. But you're very much knowledgeable about what's needed and the challenges in this check area, so 👍

Copy link
Member

@signekb signekb left a comment

Choose a reason for hiding this comment

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

Nice work 👍 Just a suggestion and a question to help me understand 🔍

seedcase_sprout/core/checks/exclude_errors.py Outdated Show resolved Hide resolved
"json_path,matcher,expected",
[
("$.match", None, True),
("$.no.match", "", False),
Copy link
Member

Choose a reason for hiding this comment

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

There might be a very basic answer to this but why do we want the match to be false here, while the message is matched (True) when the matcher is an empty string (L12)?
Same with the validator below (L61)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not very solid reasons 😅! I was thinking:

  • message_matches should check if the matcher message is a substring of the error message. Doesn't matter that much if "" matches or not?
  • json_path_matches should check if the matcher json path is exactly the full path or exactly the very last field. "" is neither, so I made it not match anything.
  • validator_matches should check if the matcher validator is exactly the validator of the error. "" is not a validator, so I made it not match.

We can refine the behaviour further for sure!

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I think that makes sense! Thanks for elaborating 👍

@lwjohnst86 lwjohnst86 merged commit 9e0899e into main Jan 23, 2025
3 checks passed
@lwjohnst86 lwjohnst86 deleted the feat/add-check-error-matcher branch January 23, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants