<commit_before>"""Exceptions used by basic support utilities."""
__author__ = "<NAME>"
import inspect
import sys
import textwrap

from pylearn2.utils.common_strings import environment_variable_essay


class EnvironmentVariableError(Exception):
    """
    An exception raised when a required environment variable is not defined
    """

    def __init__(self, *args):
        super(EnvironmentVariableError, self).__init__(*args)


# This exception is here as string_utils need it and setting it in
# datasets.exc would create a circular import.
class NoDataPathError(EnvironmentVariableError):
    """
    Exception raised when PYLEARN2_DATA_PATH is required but has not been
    defined.
    """
    def __init__(self):
        """
        .. todo::

            WRITEME
        """
        super(NoDataPathError, self).__init__(data_path_essay +
                                              environment_variable_essay)

data_path_essay = """\
You need to define your PYLEARN2_DATA_PATH environment variable. If you are
using a computer at LISA, this should be set to /data/lisa/data.
"""


def reraise_as(new_exc):
    """
    Parameters
    ----------
    new_exc : Exception isinstance
        The new error to be raised e.g. (ValueError("New message"))
        or a string that will be prepended to the original exception
        message

    Examples
    --------
    >>> try:
    >>>     do_something_crazy()
    >>> except Exception:
    >>>     reraise_as(UnhandledException("Informative message"))
    """
    orig_exc_type, orig_exc_value, orig_exc_traceback = sys.exc_info()

    if isinstance(new_exc, basestring):
        new_exc = orig_exc_type(new_exc)

    if hasattr(new_exc, 'args') and len(new_exc.args) > 0:
        new_message = new_exc.args[0]
        new_message += ('\n\nOriginal exception:\n\t' + orig_exc_type.__name__)
        if hasattr(orig_exc_value, 'args') and len(orig_exc_value.args) > 0:
            new_message += ': ' + orig_exc_value.args[0]
        new_exc.args = (new_message,) + new_exc.args[1:]

    new_exc.__cause__ = orig_exc_value
    raise type(new_exc), new_exc, orig_exc_traceback
<commit_msg>Append original exception message even if no new exception message is set<commit_after>"""Exceptions used by basic support utilities."""
__author__ = "<NAME>"
import inspect
import sys
import textwrap

from pylearn2.utils.common_strings import environment_variable_essay


class EnvironmentVariableError(Exception):
    """
    An exception raised when a required environment variable is not defined
    """

    def __init__(self, *args):
        super(EnvironmentVariableError, self).__init__(*args)


# This exception is here as string_utils need it and setting it in
# datasets.exc would create a circular import.
class NoDataPathError(EnvironmentVariableError):
    """
    Exception raised when PYLEARN2_DATA_PATH is required but has not been
    defined.
    """
    def __init__(self):
        """
        .. todo::

            WRITEME
        """
        super(NoDataPathError, self).__init__(data_path_essay +
                                              environment_variable_essay)

data_path_essay = """\
You need to define your PYLEARN2_DATA_PATH environment variable. If you are
using a computer at LISA, this should be set to /data/lisa/data.
"""


def reraise_as(new_exc):
    """
    Parameters
    ----------
    new_exc : Exception isinstance
        The new error to be raised e.g. (ValueError("New message"))
        or a string that will be prepended to the original exception
        message

    Examples
    --------
    >>> try:
    >>>     do_something_crazy()
    >>> except Exception:
    >>>     reraise_as(UnhandledException("Informative message"))
    """
    orig_exc_type, orig_exc_value, orig_exc_traceback = sys.exc_info()

    if isinstance(new_exc, basestring):
        new_exc = orig_exc_type(new_exc)

    if hasattr(new_exc, 'args'):
        if len(new_exc.args) > 0:
            new_message = new_exc.args[0]
        else:
            new_message = ""
        new_message += ('\n\nOriginal exception:\n\t' + orig_exc_type.__name__)
        if hasattr(orig_exc_value, 'args') and len(orig_exc_value.args) > 0:
            new_message += ': ' + orig_exc_value.args[0]
        new_exc.args = (new_message,) + new_exc.args[1:]

    new_exc.__cause__ = orig_exc_value
    raise type(new_exc), new_exc, orig_exc_traceback

{'fraction_non_alphanumeric': 0.10056753688989785, 'fraction_numerical': 0.0036322360953461976, 'mean_word_length': 2.831304347826087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4188184', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1276, 'n_words': 351}