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

Use paths to identify when a rule fails #1507

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

henriquemoody
Copy link
Member

@henriquemoody henriquemoody commented Dec 22, 2024

When nested-structural validation fails, it's challenging to identify which rule failed from the main exception message. A great example is the Issue796Test.php file. The exception message says:

host must be a string

But you're left unsure whether it's the host key from the mysql key or the postgresql key.

This commit changes that behaviour by introducing the concept of "Path." The path represents the path that a rule has taken, and we can use it in structural rules to identify the path of an array or object.

Here's what it looks like before and after:

-host must be a string
+`.mysql.host` must be a string

Because paths are a specific concept, I added a dot (.) at the beginning of all paths when displaying them. I was inspired by the jq syntax. I also added backticks around paths to distinguish them from any other value.

I didn't manage to fix a test, and I skipped it instead of fixing it because I want to make changes in how we display error messages as arrays, and it will be easier to fix it then.

library/Rules/Lazy.php Outdated Show resolved Hide resolved
@henriquemoody henriquemoody force-pushed the core/result-path branch 2 times, most recently from 1d8934d to a4c83a7 Compare December 22, 2024 06:01
@henriquemoody henriquemoody added this to the 3.0 milestone Dec 26, 2024
@henriquemoody henriquemoody force-pushed the core/result-path branch 3 times, most recently from 882e18a to fdf13fd Compare December 27, 2024 00:52
@henriquemoody henriquemoody force-pushed the core/result-path branch 3 times, most recently from 2ca49bb to 41fee0f Compare December 27, 2024 15:55
@henriquemoody henriquemoody force-pushed the core/result-path branch 2 times, most recently from 89b9d8e to cccd28d Compare December 27, 2024 20:33
Copy link

codecov bot commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.69%. Comparing base (a0d6355) to head (1915b6f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1507      +/-   ##
============================================
+ Coverage     96.64%   96.69%   +0.04%     
- Complexity      999     1014      +15     
============================================
  Files           205      205              
  Lines          2477     2511      +34     
============================================
+ Hits           2394     2428      +34     
  Misses           83       83              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@henriquemoody henriquemoody force-pushed the core/result-path branch 3 times, most recently from 6085889 to 661ce71 Compare December 27, 2024 21:57
@henriquemoody henriquemoody changed the title Trace paths instead of IDs Use paths to identify when a rule fails Dec 27, 2024
When nested-structural validation fails, it's challenging to identify
which rule failed from the main exception message. A great example is
the `Issue796Test.php` file. The exception message says:

host must be a string

But you're left unsure whether it's the `host` key from the `mysql` key
or the `postgresql` key.

This commit changes that behaviour by introducing the concept of "Path."
The `path` represents the path that a rule has taken, and we can use it
in structural rules to identify the path of an array or object.

Here's what it looks like before and after:

```diff
-host must be a string
+`.mysql.host` must be a string
```

Because paths are a specific concept, I added a dot (`.`) at the
beginning of all paths when displaying them. I was inspired by the `jq`
syntax. I also added backticks around paths to distinguish them from any
other value.

I didn't manage to fix a test, and I skipped it instead of fixing it
because I want to make changes in how we display error messages as
arrays, and it will be easier to fix it then.
@henriquemoody henriquemoody marked this pull request as ready for review December 27, 2024 22:31
@henriquemoody henriquemoody merged commit 1915b6f into Respect:main Dec 27, 2024
8 checks passed
@henriquemoody henriquemoody deleted the core/result-path branch December 27, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant