<commit_before>import logging
from pecan import expose, response, request


logger = logging.getLogger(__name__)
schema_logger = logging.getLogger("%s.schema" % __name__)


class ErrorController(object):

    @expose('json')
    def schema(self, **kw):
        response.status = 400
        schema_logger.error(request.validation_error)
        path = request.validation_error._format_path()
        message = '%s%sfailed validation, %s' % (
            path,
            '' if path.endswith(' ') else ' ',
            request.validation_error.reason
        )
        return dict(message=message)

    @expose('json')<commit_msg>report nicely when invalid JSON is received<commit_after>import logging
from pecan import expose, response, request


logger = logging.getLogger(__name__)
schema_logger = logging.getLogger("%s.schema" % __name__)


class ErrorController(object):

    @expose('json')
    def schema(self, **kw):
        response.status = 400
        schema_logger.error(request.validation_error)
        try:
            path = request.validation_error._format_path()
            message = '%s%sfailed validation, %s' % (
                path,
                '' if path.endswith(' ') else ' ',
                request.validation_error.reason
            )
        except AttributeError:
            message = "invalid JSON was received"
        return dict(message=message)

    @expose('json')
{'fraction_non_alphanumeric': 0.10866477272727272, 'fraction_numerical': 0.004261363636363636, 'mean_word_length': 2.612820512820513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4639472', 'n_tokens_mistral': 390, 'n_tokens_neox': 370, 'n_words': 85}