-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
Removes segfault when parsing grammar with missing symbols. Adds friendly error message. #5950
Removes segfault when parsing grammar with missing symbols. Adds friendly error message. #5950
Conversation
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.
Should we move this validation logic into grammar_parser::parse
so that it is performed during initialization?
92ee631
to
d39dc65
Compare
That's a good call. I think I moved it into this function because that's where the segfault call stack was originating from, but you're right -- I think that's the better place to put it. Just amended the PR with a new commit that moves it. Definitely a few more lines of code to put it here (the With where it's at currently, the segfault is back, but it still gives a friendly error message. This is the current behavior:
Any other suggestions for this? I definitely think we'll need to address a more graceful handling of bad parse errors (especially if we're going to address the way that it crashes the server when a bad grammar is passed in an API call) -- happy to address that in this PR, or in another one. I haven't fully mapped that strategy out in my head yet, so that's the main reason why I didn't tackle it here. |
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.
Great!
Regarding error handling - now that parse()
returns an empty state we can check for that and handle it more gracefully
I was able to confirm that this fixes #4492. |
This adds a friendly error message to help debug GBNF parsing errors. When developing a new grammar recently, I didn't realize that I had some typos in my identifier names, and it caused me some amount of headache until I figured it out.
This addition will raise an exception when parsing grammars that have undefined symbols.
Example: Create "chess_bad.gbnf" and comment out the definition of
nonpawn
.Then run it with your favorite model:
Before:
After this fix:
It's not much, but in my case it telling me the name of the missing identifier was invaluable, and hopefully this can be of help to others!
This also nicely removes crashing due to segfault, which may be of help to things like #4066 or #3878.