<commit_before>/*
 * Copyright 2013-2015, All Rights Reserved.
 *
 * Code licensed under the BSD License:
 * https://github.com/node-gh/gh/blob/master/LICENSE.md
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

'use strict';

var clc = require('cli-color'),
    fs = require('fs'),
    handlebars = require('handlebars'),
    moment = require('moment'),
    path = require('path'),
    wrap = require('wordwrap').hard(0, 80);

var slice = Array.prototype.slice,
    stripHandlebarsNewLine = function(str) {
        return str.replace(/[\s\t\r\n](\{\{[#\/])/g, '$1');
    };

function logger() {
}

logger.error = function() {
    arguments[0] = 'fatal: ' + arguments[0];
    console.error.apply(this, arguments);
    process.exit(1);
};

logger.warn = function() {
    arguments[0] = 'warning: ' + arguments[0];
    console.error.apply(this, arguments);
};

logger.info = function() {
    console.info.apply(this, arguments);
};

logger.log = function() {
    console.log.apply(this, arguments);
};

logger.success = function() {
    console.log.apply(this, arguments);
};

logger.getDuration = function(start, opt_end) {
    if (opt_end === undefined) {
        opt_end = Date.now();
    }

    return moment.duration(moment(start).diff(opt_end)).humanize(true);
};

logger.applyReplacements = function(output, replaceMap) {
    var regexPattern;

    for (regexPattern in replaceMap) {
        if (replaceMap.hasOwnProperty(regexPattern)) {
            output = output.replace(
                new RegExp(regexPattern, 'g'), replaceMap[regexPattern]);
        }
    }

    return output;
};

logger.getErrorMessage = function(err) {
    var msg;

    // General normalizer
    if (err.errors) {
        return err.errors;
    }

    // Normalize github api error
    if (!err.message) {
        return err;
    }

    try {
        msg = JSON.parse(err.message);
    } catch(e) {
        logger.warn('Unparsable response: ' + e);
        return err.message;
    }

    if (typeof msg === 'string') {
        return msg;
    }

    if (msg.errors && msg.errors[0] && msg.errors[0].message) {
        return msg.errors[0].message;
    }

    if (msg.message) {
        return msg.message;
    }

    // Normalize git error
    return err.message.replace('Command failed: fatal: ', '').trim();<commit_msg>Adding msg for when the error object isn't defined for the getErrorMessage method.<commit_after>/*
 * Copyright 2013-2015, All Rights Reserved.
 *
 * Code licensed under the BSD License:
 * https://github.com/node-gh/gh/blob/master/LICENSE.md
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

'use strict';

var clc = require('cli-color'),
    fs = require('fs'),
    handlebars = require('handlebars'),
    moment = require('moment'),
    path = require('path'),
    wrap = require('wordwrap').hard(0, 80);

var slice = Array.prototype.slice,
    stripHandlebarsNewLine = function(str) {
        return str.replace(/[\s\t\r\n](\{\{[#\/])/g, '$1');
    };

function logger() {
}

logger.error = function() {
    arguments[0] = 'fatal: ' + arguments[0];
    console.error.apply(this, arguments);
    process.exit(1);
};

logger.warn = function() {
    arguments[0] = 'warning: ' + arguments[0];
    console.error.apply(this, arguments);
};

logger.info = function() {
    console.info.apply(this, arguments);
};

logger.log = function() {
    console.log.apply(this, arguments);
};

logger.success = function() {
    console.log.apply(this, arguments);
};

logger.getDuration = function(start, opt_end) {
    if (opt_end === undefined) {
        opt_end = Date.now();
    }

    return moment.duration(moment(start).diff(opt_end)).humanize(true);
};

logger.applyReplacements = function(output, replaceMap) {
    var regexPattern;

    for (regexPattern in replaceMap) {
        if (replaceMap.hasOwnProperty(regexPattern)) {
            output = output.replace(
                new RegExp(regexPattern, 'g'), replaceMap[regexPattern]);
        }
    }

    return output;
};

logger.getErrorMessage = function(err) {
    var msg;

    // General normalizer
    if (!err) {
        return 'No error message.';
    }

    if (err.errors) {
        return err.errors;
    }

    // Normalize github api error
    if (!err.message) {
        return err;
    }

    try {
        msg = JSON.parse(err.message);
    } catch(e) {
        logger.warn('Unparsable response: ' + e);
        return err.message;
    }

    if (typeof msg === 'string') {
        return msg;
    }

    if (msg.errors && msg.errors[0] && msg.errors[0].message) {
        return msg.errors[0].message;
    }

    if (msg.message) {
        return msg.message;
    }

    // Normalize git error
    return err.message.replace('Command failed: fatal: ', '').trim();
{'fraction_non_alphanumeric': 0.163449433487201, 'fraction_numerical': 0.00839278220730172, 'mean_word_length': 2.6953488372093024, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '4281875', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1500, 'n_words': 321}