Repository navigation
Conversation
This change updates the database wrapper generator to correctly catch sql.ErrNoRows and return our custom ErrNotFound error instead. This ensures consistency across the different database backends (SQLite, Postgres, MySQL) and simplifies error handling in the application layer. The generator now includes checks for sql.ErrNoRows in both the loop-based handlers and the direct return handlers.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant improvement to the application's database interaction layer by standardizing how "record not found" errors are handled. By modifying the database wrapper generator to catch Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a great improvement by abstracting sql.ErrNoRows into a custom database.ErrNotFound. This simplifies error handling throughout the application and makes the database layer more consistent. The changes are well-executed across the generator, application code, and tests.
I've added one suggestion to refactor the error handling logic in the database wrapper generator. This will reduce code duplication in the generated files and also fix a potential latent bug.
@gemini-code-assist I don't see your suggestion. |
|
Hello @kalbasit, I apologize that the suggestion was not visible. It seems there might have been an issue with how the comment was posted. I intended to provide a suggestion for refactoring the error handling logic in the Problem DescriptionThe current template generates repetitive Suggested RefactoringTo address both the code duplication and the latent bug, I suggest introducing a helper template function. This function would encapsulate the logic for returning the appropriate zero value along with the specified error. This makes the generated code cleaner and ensures consistent error handling. Here's the suggested template definition to be added to {{- define "handleErrorReturn" -}}
{{- $retType := .Method.ReturnType -}}
{{- if .Method.ReturnsSelf -}}
return nil, {{.ErrorVar}} // Assuming Querier methods return (Querier, error)
{{- else if not .Method.HasValue -}}
return {{.ErrorVar}}
{{- else if isSlice $retType -}}
return nil, {{.ErrorVar}}
{{- else if isDomainStruct .Method.ReturnElem -}}
return {{.Method.ReturnElem}}{}, {{.ErrorVar}}
{{- else -}}
return {{zeroValue $retType}}, {{.ErrorVar}}
{{- end -}}
{{- end -}}And then, replace the existing {{/* 2. HANDLE ERROR */}}
{{- if .Method.ReturnsError}}
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
{{- template "handleErrorReturn" (dict "Method" .Method "ErrorVar" "ErrNotFound") -}}
}
{{- template "handleErrorReturn" (dict "Method" .Method "ErrorVar" "err") -}}
}
{{- end}}This change ensures that |
This change introduces a helper template handleErrorReturn to reduce code duplication and fix a latent bug where errors were swallowed for methods returning (Querier, error).
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the database layer to abstract away sql.ErrNoRows into a domain-specific database.ErrNotFound. The changes are implemented cleanly by updating the database wrapper generator with a new handleErrorReturn template, which improves code generation and maintainability. The updates are consistently applied across all database backends (MySQL, PostgreSQL, SQLite) and all call sites have been updated to use the new database.IsNotFoundError function. The test suite has also been updated accordingly. Overall, this is a solid improvement for error handling consistency. I've found one minor issue in a test case that I've commented on.

This change updates the database wrapper generator to correctly catch
sql.ErrNoRows and return our custom ErrNotFound error instead. This ensures
consistency across the different database backends (SQLite, Postgres, MySQL)
and simplifies error handling in the application layer.
The generator now includes checks for sql.ErrNoRows in both the loop-based
handlers and the direct return handlers.