def _format_exception_message()

in src/sagemaker_sklearn_container/exceptions.py [0:0]


    def _format_exception_message(message, caused_by):
        """Generates the exception message.
        If a message has been explicitly passed then we use that as the exception
        message. If we also know the underlying exception type we prepend that
        to the name.
        If there is no message but we have an underlying exception then we use
        that exceptions message and prepend the type of the exception.
        """
        if message:
            formatted_message = message
        elif caused_by:
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")  # Suppress deprecation warning
                formatted_message = getattr(caused_by, "message", str(caused_by))
        else:
            formatted_message = "unknown error occurred"

        if caused_by:
            formatted_message += f" (caused by {caused_by.__class__.__name__})"

        return formatted_message