-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Bug
Close() currently panics if called when a session hasn't been established (e.g., if session creation failed during initialization). The method attempts to access c.session.SessionID without verifying that c.session is non-nil.
Fix
Added a guard clause to return an error instead of panicking when the session is nil.
func (c *MessageSessionClient) Close(ctx context.Context) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.session == nil {
return fmt.Errorf("cannot close: no active session found")
}
return c.deleteMessageSession(ctx, c.scaleSetID, c.session.SessionID)
}Test Case
Verified the fix with the following unit test:
func TestMessageSessionClient_Close_NilSession(t *testing.T) {
client := &MessageSessionClient{session: nil}
err := client.Close(context.Background())
if err == nil {
t.Fatal("expected error when closing nil session, got nil")
}
if !strings.Contains(err.Error(), "no active session") {
t.Errorf("unexpected error message: %v", err)
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels