adk-go icon indicating copy to clipboard operation
adk-go copied to clipboard

Feature/session service well known error

Open FamALouiz opened this issue 1 month ago • 6 comments

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.

FamALouiz avatar Nov 24 '25 21:11 FamALouiz

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 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 :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-code-assist[bot] avatar Nov 24 '25 21:11 gemini-code-assist[bot]

/gemini review

FamALouiz avatar Nov 24 '25 22:11 FamALouiz

/gemini review

kdroste-google avatar Nov 28 '25 14:11 kdroste-google

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

FamALouiz avatar Nov 28 '25 16:11 FamALouiz

/gemini review

FamALouiz avatar Nov 28 '25 19:11 FamALouiz

/gemini review

FamALouiz avatar Nov 28 '25 20:11 FamALouiz