<commit_before>import json
import os
import sys
from termcolor import colored


CONFIG_FILE_PATH = os.path.abspath("config.json")


class HeaderNotFound(Exception):
    pass


def config_cache(pass_func):
    try:
        with open(CONFIG_FILE_PATH, 'r') as config:
            c_cache = json.load(config)
    except IOError:
        sys.stderr.write(
            colored("ERROR: Couldn't load config file.  Exiting.", 'red')
        )
        sys.stderr.flush()
        os.exit(1)
    except ValueError:  # Error on loading the json itself.
        sys.stderr.write(
            colored(
                "ERROR: Couldn't load config file JSON. Formatting error?",
                'red'
            )
        )
        sys.stderr.flush()
        os.exit(1)

    def dummy_config(header):
        if header in c_cache:
            return c_cache[header]
        raise HeaderNotFound

    return dummy_config


@config_cache
def load_config():
    pass<commit_msg>Refactor config.py to use fallback error handeling<commit_after>import json
import os
import sys
from logger.fallback import error


CONFIG_FILE_PATH = os.path.abspath("config.json")


class HeaderNotFound(Exception):
    pass


def config_cache(pass_func):
    try:
        with open(CONFIG_FILE_PATH, 'r') as config:
            c_cache = json.load(config)
    except IOError:
        error("Couldn't load config file.  Exiting.")
        sys.stderr.flush()
        os.exit(1)
    except ValueError:  # Error on loading the json itself.
        error("Couldn't load config file JSON. Formatting error?")
        error("System shutting down.")
        sys.stderr.flush()
        os.exit(1)

    def dummy_config(header):
        if header in c_cache:
            return c_cache[header]
        raise HeaderNotFound

    return dummy_config


@config_cache
def load_config():
    pass
{'fraction_non_alphanumeric': 0.08829902491874322, 'fraction_numerical': 0.0021668472372697724, 'mean_word_length': 2.3159784560143626, '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': '3970199', 'n_tokens_mistral': 549, 'n_tokens_neox': 530, 'n_words': 149}