Feature/session service well known error
Session Service: Well-Known Error Handling
Resolves #85
This PR introduces standardized error handling for the session service by creating well-known errors and updating both in-memory and database implementations to use them consistently.
Changes Made
1. Created Well-Known Errors (session/errors.go)
- Added
ErrSessionNotFound- returned when a session cannot be found - Moved
ErrStateKeyNotExist- returned when a state key doesn't exist
2. Updated Session Service Implementations
Database Service (session/database/service.go)
- Modified
Get()to returnErrSessionNotFoundwhengorm.ErrRecordNotFoundis encountered - Modified
Delete()to returnErrSessionNotFoundwhen no rows are affected (session doesn't exist) - Improved error messages with contextual information (session ID)
In-Memory Service (session/inmemory.go)
- Updated
Get()to returnErrSessionNotFoundinstead of generic error - Updated
AppendEvent()to returnErrSessionNotFoundwhen session is not found - Improved error messages with contextual information (session ID)
3. Test Improvements
Added Test Helper Function
- Created
checkTestError()helper to eliminate code duplication across test files - Uses
t.Fatalf()for immediate test termination on error, ensuring consistent error handling - Applied to both
service_test.goandinmemory_test.go
Breaking Change Note
This changes the error behavior for Delete() operations - previously, deleting a non-existent session returned no error, but now returns ErrSessionNotFound. This aligns the behavior between database and in-memory implementations.
Summary of Changes
Hello @FamALouiz, I'm Gemini Code Assist[^1]! 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 focuses on enhancing the session service's error handling by introducing standardized, well-known error types. It centralizes common error definitions and updates both the database and in-memory session implementations to consistently utilize these new error types, particularly ErrSessionNotFound. This change significantly improves error clarity and consistency across the service, making it easier for consumers to identify and handle specific error conditions, and also includes improvements to test utilities.
Highlights
- Standardized Error Handling: Introduced
ErrSessionNotFoundand centralized error definitions in a newsession/errors.gofile, along with movingErrStateKeyNotExistthere. - Database Service Updates: Modified
Get()andDelete()methods in the database service to consistently returnsession.ErrSessionNotFoundwhen a session is not found, improving error clarity and providing contextual session IDs. - In-Memory Service Updates: Updated
Get()andAppendEvent()methods in the in-memory service to also returnsession.ErrSessionNotFoundfor non-existent sessions, ensuring consistent error behavior across implementations. - Test Utility Enhancement: Added a
checkTestError()helper function to streamline error validation in test files (service_test.goandinmemory_test.go), reducing code duplication and ensuring consistent test error handling. - Breaking Change Noted: The
Delete()operation now returnsErrSessionNotFoundwhen attempting to delete a non-existent session, which is a change from its previous behavior of returning no error.
Using Gemini Code Assist
The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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 :thumbsup: and :thumbsdown: 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.
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
/gemini review
/gemini review
I'll take a look at the requested changes and get this PR going. Thanks @kdroste-google
/gemini review
/gemini review