feat(go): add HandlerFunc for error-returning handlers#4805
feat(go): add HandlerFunc for error-returning handlers#4805dmeremyanin wants to merge 1 commit intofirebase:mainfrom
Conversation
Summary of ChangesHello @dmeremyanin, 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 enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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
The pull request introduces genkit.HandlerFunc to provide an error-returning HTTP handler, which is beneficial for integration with frameworks that have centralized error handling. The changes include updates to servers.go to implement HandlerFunc and modify Handler to wrap HandlerFunc. The README.md has been updated to document the new HandlerFunc and its use cases. Additionally, servers_test.go has been significantly expanded to include comprehensive tests for both Handler and HandlerFunc, covering various success and error scenarios, including streaming and durable streaming. The test cases for Handler now verify error wrapping behavior, while HandlerFunc tests focus on the returned error. Overall, the changes are well-implemented and tested, improving the flexibility of Genkit's HTTP handling.
| panic(fmt.Errorf("genkit.HandlerFunc: error applying options: %w", err)) | ||
| } |
There was a problem hiding this comment.
| if !strings.Contains(string(body), `"test-input"`) { | ||
| t.Errorf("want response to contain test-input, got %q", string(body)) | ||
| } |
There was a problem hiding this comment.
The error message here is slightly off. It should be want response to contain 'test-input', got %q to match the expected string. Also, the single quotes around test-input are missing in the current message.
| if !strings.Contains(string(body), `"test-input"`) { | |
| t.Errorf("want response to contain test-input, got %q", string(body)) | |
| } | |
| if !strings.Contains(string(body), `"test-input"`) { | |
| t.Errorf("want response to contain \"test-input\", got %q", string(body)) | |
| } |
| if !strings.Contains(string(body), "action-context-value") { | ||
| t.Errorf("want response to containaction-context-value, got %q", string(body)) | ||
| t.Errorf("want response to contain action-context-value, got %q", string(body)) | ||
| } |
There was a problem hiding this comment.
The error message here has a typo: containaction-context-value. It should be contain 'action-context-value'.
| if !strings.Contains(string(body), "action-context-value") { | |
| t.Errorf("want response to containaction-context-value, got %q", string(body)) | |
| t.Errorf("want response to contain action-context-value, got %q", string(body)) | |
| } | |
| if !strings.Contains(string(body), "action-context-value") { | |
| t.Errorf("want response to contain 'action-context-value', got %q", string(body)) | |
| } |
| if !strings.Contains(string(body), "value1,value2") { | ||
| t.Errorf("want response to contain value1,value2, got %q", string(body)) | ||
| } |
There was a problem hiding this comment.
The error message here has a typo: contain value1,value2. It should be contain 'value1,value2'.
| if !strings.Contains(string(body), "value1,value2") { | |
| t.Errorf("want response to contain value1,value2, got %q", string(body)) | |
| } | |
| if !strings.Contains(string(body), "value1,value2") { | |
| t.Errorf("want response to contain 'value1,value2', got %q", string(body)) | |
| } |
f7be254 to
b892d7e
Compare
Fixes #4801
Adds
genkit.HandlerFuncthat returns errors instead of writing them to responses, enabling integration with frameworks expecting error-returning handlers (Echo, Fiber, etc).genkit.Handleris now just a wrapper forgenkit.HandlerFunc. All existing tests forgenkit.Handlerhave been adapted forgenkit.HandlerFunc, since it now holds the business logic. Added tests forgenkit.Handlerverify the error wrapping behavior.Checklist (if applicable):