Skip to content

Conversation

@FamALouiz
Copy link

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 return ErrSessionNotFound when gorm.ErrRecordNotFound is encountered
  • Modified Delete() to return ErrSessionNotFound when 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 return ErrSessionNotFound instead of generic error
  • Updated AppendEvent() to return ErrSessionNotFound when 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.go and inmemory_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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @FamALouiz, 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 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 ErrSessionNotFound and centralized error definitions in a new session/errors.go file, along with moving ErrStateKeyNotExist there.
  • Database Service Updates: Modified Get() and Delete() methods in the database service to consistently return session.ErrSessionNotFound when a session is not found, improving error clarity and providing contextual session IDs.
  • In-Memory Service Updates: Updated Get() and AppendEvent() methods in the in-memory service to also return session.ErrSessionNotFound for 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.go and inmemory_test.go), reducing code duplication and ensuring consistent test error handling.
  • Breaking Change Noted: The Delete() operation now returns ErrSessionNotFound when 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 👍 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

  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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a good job of standardizing error handling by introducing ErrSessionNotFound and refactoring tests with a helper function. The changes to the database service implementation are correct. However, there are several critical issues that need to be addressed. The in-memory service's Delete method was not updated to return the new error, which undermines the goal of consistent behavior. Additionally, multiple tests that were updated to expect ErrSessionNotFound only check for the presence of an error, not the specific error type, which could hide bugs. There are also some minor inconsistencies in test naming and error message formatting that should be fixed.

FamALouiz and others added 9 commits November 24, 2025 22:27
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@FamALouiz
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of standardizing error handling by introducing ErrSessionNotFound and applying it consistently across both the database and in-memory implementations of the session service. This significantly improves the predictability and robustness of the service. The test updates are thorough and correctly validate the new error behavior.

I have a few suggestions for improvement:

  • One comment in session/database/service.go has become outdated due to the changes and should be updated to avoid confusion.
  • The error handling logic in the tests within session/inmemory_test.go is slightly inconsistent with the patterns in session/database/service_test.go. Aligning these would improve maintainability. The PR description mentions a checkTestError() helper function, which would be an excellent way to enforce this consistency.

Overall, these are solid improvements that enhance the quality of the codebase.

FamALouiz and others added 2 commits November 24, 2025 23:26
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kdroste-google
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively standardizes error handling for the session service by introducing ErrSessionNotFound and ensuring its consistent use in both the database and in-memory implementations. This is a great improvement for the robustness and predictability of the API. The refactoring to rename variables that shadowed the session package name and fixing test names also improves code clarity. The tests have been properly updated to assert the new error behavior. My main suggestion is to reduce code duplication in the test files, which would further improve maintainability.

@FamALouiz
Copy link
Author

I'll take a look at the requested changes and get this PR going. Thanks @kdroste-google

@FamALouiz
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively standardizes error handling by introducing well-known errors, which significantly improves consistency between the database and in-memory session service implementations. The alignment of the Delete operation's behavior is a notable improvement. Additionally, the refactoring of tests to use a helper function for error checking cleans up the test code nicely. I have one suggestion regarding code duplication in the test helpers.

@FamALouiz FamALouiz force-pushed the feature/session-service-well-known-error branch from 8839c34 to e74b07c Compare November 28, 2025 20:49
@FamALouiz
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces standardized error handling for the session service by creating a well-known ErrSessionNotFound error. The changes are excellent, updating both the database and in-memory implementations to use this error consistently, which improves the robustness and predictability of the service. The alignment of behavior for Delete operations on non-existent sessions is a particularly valuable consistency fix. Additionally, the new AssertTestError test helper effectively simplifies and cleans up the test code. The code quality is high, and the changes are well-tested. I have no further recommendations as no issues of medium or higher severity were found.

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.

sessionservice: Introduce a well know "not exists" to sessionservice

2 participants