code: def handle_exceptions_in_retries(
      no_retry_exceptions: Tuple[Type[Exception], ...],
      retry_exceptions: Tuple[Type[Exception], ...],
      suppress_errors: bool,
      check_message_contains: Optional[str],
      last_retry: bool,
      logger: Optional[Logger],
      wrap_error_message_in: Optional[str],
  ) -> Generator[None, None, None]:
      try:
          yield  # Perform action within the context manager.
      except no_retry_exceptions:
          raise
      except retry_exceptions as err:  # Exceptions is a tuple.
          err_msg = getattr(err, "message", repr(err))
  
          if not last_retry or suppress_errors:
              # We are either explicitly asked to suppress the error
              # or we have retries left.
              if logger is not None:
                  # `logger.exception` automatically logs `err` and its stack trace.
                  logger.exception(err)
  
          elif (
              not last_retry
              and check_message_contains is not None
              and any(
                  message in err_msg
                  for message in check_message_contains
              )
          ):
              # In this case, the error is just logged, suppressed and default
              # value returned
              if logger is not None:
                  logger.exception(wrap_error_message_in)
  
          elif not wrap_error_message_in:
              raise
  
          else:
              msg = f"{wrap_error_message_in}: {type(err).__name__}: {str(err)}"
              raise type(err)(msg).with_traceback(err.__traceback__)
  
file_path: Ax/ax/utils/common/executils.py
imports: import asyncio
  import functools
  import time
  from contextlib import contextmanager
  from logging import Logger
  from typing import Any, Generator, List, Optional, Tuple, Type
label_desc: Use image node_id 2 for calling a global function with example usage: handle_exceptions_in_retries(no_retry_exceptions, retry_exceptions, suppress_errors, check_message_contains, last_retry, logger, wrap_error_message_in) without return types