code: def catch_game_end(func):
      """Decorator to handle 'Game has already ended' exceptions."""
  
      @functools.wraps(func)
      def _catch_game_end(self, *args, **kwargs):
          """Decorator to handle 'Game has already ended' exceptions."""
          prev_status = self.status
          try:
              return func(self, *args, **kwargs)
          except protocol.ProtocolError as protocol_error:
              if prev_status == Status.in_game and (
                  "Game has already ended" in str(protocol_error)
              ):
                  # It's currently possible for us to receive this error even though
                  # our previous status was in_game. This shouldn't happen according
                  # to the protocol. It does happen sometimes when we don't observe on
                  # every step (possibly also requiring us to be playing against a
                  # built-in bot). To work around the issue, we catch the exception
                  # and so let the client code continue.
                  logging.warning(
                      "Received a 'Game has already ended' error from SC2 whilst status "
                      "in_game. Suppressing the exception, returning None."
                  )
  
                  return None
              else:
                  raise
  
      return _catch_game_end
  
imports: import copy
  import functools
  import socket
  import sys
  import time
  from absl import flags
  from absl import logging
  from pysc2.lib import protocol
  from pysc2.lib import static_data
  from pysc2.lib import stopwatch
  import websocket
  from s2clientprotocol import debug_pb2
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 5 for calling a global function with example usage: catch_game_end(func) and returns: _catch_game_end, func, None