<commit_before>// Load modules

var Hoek = require('hoek');
var Language = require('./language');


// Declare internals

var internals = {};


internals.Err = function (type, context, state, options) {

    this.type = type;
    this.context = context || {};
    this.context.key = state.key;
    this.path = state.path;
    this.options = options;
};


internals.Err.prototype.toString = function () {

    var self = this;

    var localized = this.options.language;
    this.context.key = this.context.key || localized.root || Language.errors.root;

    var format = Hoek.reach(localized, this.type) || Hoek.reach(Language.errors, this.type);
    var hasKey = /\{\{\!?key\}\}/.test(format);
    format = (hasKey ? format : '{{!key}} ' + format);
    var message = format.replace(/\{\{(\!?)([^}]+)\}\}/g, function ($0, isSecure, name) {

        var value = Hoek.reach(self.context, name);
        var normalized = Array.isArray(value) ? value.join(', ') : value.toString();
        return (isSecure ? Hoek.escapeHtml(normalized) : normalized);
    });

    return message;
};

internals.Err.prototype.getPath = function () {

    var self = this;

    var recursePath = function (recursedItem) {

        var reachedItem = Hoek.reach(recursedItem, 'context.reason.0');
        if (reachedItem && reachedItem.context) {
            return recursePath(reachedItem);
        }

        return recursedItem.path;
    };

    return recursePath(self) || self.path || self.context.key;

};


exports.create = function (type, context, state, options) {

    return new internals.Err(type, context, state, options);
};


exports.process = function (errors, object) {

    if (!errors || !errors.length) {<commit_msg>remove redunant self assignment<commit_after>// Load modules

var Hoek = require('hoek');
var Language = require('./language');


// Declare internals

var internals = {};


internals.Err = function (type, context, state, options) {

    this.type = type;
    this.context = context || {};
    this.context.key = state.key;
    this.path = state.path;
    this.options = options;
};


internals.Err.prototype.toString = function () {

    var self = this;

    var localized = this.options.language;
    this.context.key = this.context.key || localized.root || Language.errors.root;

    var format = Hoek.reach(localized, this.type) || Hoek.reach(Language.errors, this.type);
    var hasKey = /\{\{\!?key\}\}/.test(format);
    format = (hasKey ? format : '{{!key}} ' + format);
    var message = format.replace(/\{\{(\!?)([^}]+)\}\}/g, function ($0, isSecure, name) {

        var value = Hoek.reach(self.context, name);
        var normalized = Array.isArray(value) ? value.join(', ') : value.toString();
        return (isSecure ? Hoek.escapeHtml(normalized) : normalized);
    });

    return message;
};

internals.Err.prototype.getPath = function () {

    var recursePath = function (recursedItem) {

        var reachedItem = Hoek.reach(recursedItem, 'context.reason.0');
        if (reachedItem && reachedItem.context) {
            return recursePath(reachedItem);
        }

        return recursedItem.path;
    };

    return recursePath(this) || this.path || this.context.key;

};


exports.create = function (type, context, state, options) {

    return new internals.Err(type, context, state, options);
};


exports.process = function (errors, object) {

    if (!errors || !errors.length) {
{'fraction_non_alphanumeric': 0.16257309941520467, 'fraction_numerical': 0.0011695906432748538, 'mean_word_length': 3.038961038961039, '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': '2677556', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1046, 'n_words': 240}