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

Improve error handling in SQL parser #505

Closed

Conversation

ppichugin
Copy link

This Pull Request introduces the following improvements to the SQL parser:

  1. Added a custom GooseError type for better error handling.
  2. Replaced error strings with constants for easier maintenance.
  3. Updated error messages to be more descriptive.
  4. Added new test cases to cover various error scenarios in the TestErrorHandling function.
  5. Refactored some comments for better readability.

These improvements aim to make it easier to understand and handle errors in the SQL parser, as well as improve the overall readability and maintainability of the code.

@@ -25,6 +24,37 @@ func FromBool(b bool) Direction {
return DirectionDown
}

type GooseError string
Copy link
Collaborator

@mfridman mfridman Apr 23, 2023

Choose a reason for hiding this comment

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

I'm not convinced this makes things more readable.

The sql parser is an internal package, which means this error type isn't user-facing. Furthermore, we're not surfacing any specific information, i.e., it's still a string type which means asserting for this error would return the same error message as .Error. I think this adds more indirection.

@mfridman
Copy link
Collaborator

mfridman commented Apr 23, 2023

I'm curious, was there a specific error you were running into with the sqlparser, or does this fall into the general cleanup and maintenance group of PR's?

Thanks for putting up a PR, I think most of this makes sense minus the GooseError (which should probably be ParserError, but I still don't think we need an error type here).

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, _, err := ParseSQLMigration(strings.NewReader(test.sql), DirectionUp, false)
if err == nil || !test.errCheck(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we remove the GooseError, we can assert directly for the sentinel error with errors.Is ?

@ppichugin
Copy link
Author

Hi @mfridman ! Thanks a lot for your review and feedback!

Actually, this Pull Request was primarily for my self-assessment and a try to improve just one single part of the code in Open-Source project for better readability. My main goal was to gain a better understanding of the project's code and to test my own abilities.

For the future contributing on this project - I will definitely focus on the section "Issues" before to provide PR.

@ppichugin ppichugin closed this Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants