<commit_before>'use strict';

const fs = require('fs');
const path = require('path');

const debug = require('../util/debug')('config:home');

const mainConfigPath =
    process.env.REST_ON_COUCH_CONFIG ||
    path.resolve(require('os').homedir(), '.rest-on-couch-config');

debug(`main config path is ${mainConfigPath}`);

exports.CONFIG_FILE = mainConfigPath;
exports.config = getHomeConfig();

function getHomeConfig() {
    try {
        const config = JSON.parse(fs.readFileSync(mainConfigPath, 'utf8'));
        if (config.homeDir) {
            config.homeDir = path.resolve(mainConfigPath, '..', config.homeDir);
            debug(`homeDir is ${config.homeDir}`);
        }
        return config;
    } catch (e) {
        debug('no main config found');
        return {};
    }
}

exports.get = function (key) {
    return exports.config[key];
};<commit_msg>Add error message if config file parsing failed<commit_after>'use strict';

const fs = require('fs');
const path = require('path');

const debug = require('../util/debug')('config:home');

const mainConfigPath =
    process.env.REST_ON_COUCH_CONFIG ||
    path.resolve(require('os').homedir(), '.rest-on-couch-config');

debug(`main config path is ${mainConfigPath}`);

exports.CONFIG_FILE = mainConfigPath;
exports.config = getHomeConfig();

function getHomeConfig() {
    try {
        const config = JSON.parse(fs.readFileSync(mainConfigPath, 'utf8'));
        if (config.homeDir) {
            config.homeDir = path.resolve(mainConfigPath, '..', config.homeDir);
            debug(`homeDir is ${config.homeDir}`);
        }
        return config;
    } catch (e) {
        if(e.code === 'ENOENT') {
            debug('no main config found');
        } else {
            debug.error('Error while reading and parsing config file' + '\n' + e);
        }
        return {};
    }
}

exports.get = function (key) {
    return exports.config[key];
};
{'fraction_non_alphanumeric': 0.1581419624217119, 'fraction_numerical': 0.0010438413361169101, 'mean_word_length': 3.027310924369748, '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': '2836950', 'n_tokens_mistral': 584, 'n_tokens_neox': 583, 'n_words': 127}