From 7938377f7eac661a2d3288f69129fab2705069b2 Mon Sep 17 00:00:00 2001
From: johnnyshields <27655+johnnyshields@users.noreply.github.com>
Date: Tue, 11 Feb 2025 18:06:31 +0700
Subject: [PATCH] In the Ruby driver, there is a case where InvalidSession is
 raised instead of SessionEnded. In addition, SessionEnded should inherit from
 InvalidSession, not from just Error.

---
 lib/mongo/error/session_ended.rb | 4 ++--
 lib/mongo/session.rb             | 7 +------
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/lib/mongo/error/session_ended.rb b/lib/mongo/error/session_ended.rb
index 15d57e07d0..269378b611 100644
--- a/lib/mongo/error/session_ended.rb
+++ b/lib/mongo/error/session_ended.rb
@@ -21,9 +21,9 @@ class Error
     # Session was previously ended.
     #
     # @since 2.7.0
-    class SessionEnded < Error
+    class SessionEnded < InvalidSession
       def initialize
-        super("The session was ended and cannot be used")
+        super('The session was ended and cannot be used. Please create a new session.')
       end
     end
   end
diff --git a/lib/mongo/session.rb b/lib/mongo/session.rb
index be9c1f2a42..e3c9392a1c 100644
--- a/lib/mongo/session.rb
+++ b/lib/mongo/session.rb
@@ -297,11 +297,6 @@ def session_id
         'of the client owning this operation. Please only use this session for operations through its parent ' +
         'client.'.freeze
 
-    # Error message describing that the session cannot be used because it has already been ended.
-    #
-    # @since 2.5.0
-    SESSION_ENDED_ERROR_MSG = 'This session has ended and cannot be used. Please create a new one.'.freeze
-
     # Error message describing that sessions are not supported by the server version.
     #
     # @since 2.5.0
@@ -1251,7 +1246,7 @@ def set_operation_time(result)
     end
 
     def check_if_ended!
-      raise Mongo::Error::InvalidSession.new(SESSION_ENDED_ERROR_MSG) if ended?
+      raise Mongo::Error::SessionEnded if ended?
     end
 
     def check_matching_cluster!(client)