Skip to content

parseQuery: Return either a query or an error #178

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

Merged
merged 5 commits into from
Dec 16, 2019
Merged

parseQuery: Return either a query or an error #178

merged 5 commits into from
Dec 16, 2019

Conversation

dominikbraun
Copy link
Contributor

@dominikbraun dominikbraun commented Dec 16, 2019

This fixes #174 and #176.

parseQuery used to return a nil query and a nil error, however the code relies on the assumption that the query is always valid if the error is not nil (as explained here).

This assumption gets correct with this change. parseQuery returns either a query or and error. There's no return nil, nil anymore.

@@ -382,7 +382,7 @@ func parseQuery(c core.Catalog, stmt nodes.Node, source string) (*Query, error)
}
case nodes.UpdateStmt:
default:
return nil, nil
return nil, fmt.Errorf("parseQuery: unsupported statement type: %T", n)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a note that here and above you should file an issue if you hit this error because it's easy to see someone generating code that (should be) valid but hitting an edge case here because we haven't thought about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense because with #179, these edge cases shouldn't be hit at all. Now the user gets the following error if it happens though:

parseQuery: unsupported statement type: pg_query.CreateStmt - feel free to file an issue on GitHub

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Can we actually remove the - feel free to file an issue on GitHub from the error message? Instead of a small message for a select number of errors, I'd like to include a larger error message with links back to the project. Since that's a larger project, it should be a separate change.

@dominikbraun
Copy link
Contributor Author

Done, the error messages are uniformly again now.

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

Thanks for quick turnaround

@kyleconroy kyleconroy merged commit 9211826 into sqlc-dev:master Dec 16, 2019
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.

How to get start? I think it should be very straight forward but I only get panic error.
3 participants