def convert_to_customer_data_errors()

in src/vw-serving/src/vw_serving/sagemaker/exceptions.py [0:0]


def convert_to_customer_data_errors(exception, channel, content_type):
    """Convert exception from data iterators to customer errors.

    If exception is a BaseSdkError or not an input error, return the value of exception.

    :param exception: (Exception) exception instance
    :param channel: (str) data channel name
    :param content_type: (str) content type or None
    :return: (Exception) an instance of CustomerError or the value of exception parameter
    """

    if isinstance(exception, BaseSdkError):
        return exception

    exception_text = str(exception)
    is_nan_error = "(Input Error) (NaN)" in exception_text
    is_inf_error = "(Input Error) (Inf)" in exception_text
    is_input_error = "(Input Error)" in exception_text

    if is_nan_error:
        return CustomerError(
            "Unable to read data channel '{}'. Found missing (NaN) values. "
            "Please remove any missing (NaN) values in the input data.".format(channel), caused_by=exception)

    if is_inf_error:
        return CustomerError(
            "Unable to read data channel '{}'. Found infinite floating point values. "
            "Please remove any infinite floating point values in the input data.".format(channel),
            caused_by=exception)

    if is_input_error and content_type:
        return CustomerError(
            "Unable to read data channel '{}'. Requested content-type is '{}'. "
            "Please verify the data matches the requested content-type.".format(channel, content_type),
            caused_by=exception)

    if is_input_error:
        return CustomerError(
            "Unable to read data channel '{}'. "
            "Please verify the correct data channel configuration is provided.".format(channel),
            caused_by=exception)

    return exception