-
Notifications
You must be signed in to change notification settings - Fork 432
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
fix(structure): provide better error handling if orderings contain invalid field #5709
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
No changes to documentation |
Component Testing Report Updated Feb 26, 2024 1:12 PM (UTC)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this fully solves the problem, from my testing if you use the following ordering
{
title: 'Test',
name: 'test',
by: [
{
field: 'nonexistent',
direction: 'desc',
},
],
},
than it will not error and make a query | order(nonexistent desc)
From what I can tell this error only happens when you more than 2 fields to sort by and it fails due to running into , ,
in this line of code in groq you can query for fields non-existent and it will not error so that catch block might show this message for things that are not necessarily related to sort order of non existent fields
Thanks @binoy14! We do verify there is a missing field before displaying this particular message, but I will test it with the scenario you provided and see if I can get it to fail. |
@binoy14 - in that line you reference, that function does the same logic (it's where I got it from) and it strips out unknown fields and prints a warning message to the console (not great). I tried to make it throw an error but it ended up crashing the whole page. |
7bedc22
to
9c991ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with different scenarios and not running into same issues as before. LGTM, thanks!
…valid field (#5709) * fix(structure): provide better error handling if orderings contain invalid field * chore: fixed lint issue * chore: fixed lint issue again * fix(structure): provide better error handling if orderings contain invalid field * fix(structure): provide better error handling if orderings contain invalid field * fix(structure): add comment explaining why we are calling this method
Description
Fixes SDX-847
Previously, if an invalid field name was given for an ordering for a schema, the user would be presented with a GROQ syntax error. This change adds a check in the event of an error to look for this situation to provide a more targeted error message.
Before:
After:
What to review
I am not sure if there is a better place to put this check. Since this is part of schema setup, this error should be rare, so I did not want to add this check in for every request. This is why I put it in the catch block. There may be other scenarios we want to check for here as well.
Testing
I did manual testing. I wasn't sure how to contrive this edge case in our test bench.
Notes for release