<commit_before>#ifndef SRC_SETTINGS_JSONFILE_SETTING_BACKEND_HPP_
#define SRC_SETTINGS_JSONFILE_SETTING_BACKEND_HPP_

#include <settings/settings.hpp>
#include <cereal/archives/json.hpp>

namespace fc
{

class json_file_setting_facade
{
public:
	typedef cereal::JSONInputArchive json_archive;

	/**
	 * @brief Creates a setting facade that reads values from
	 * stream using json format.
	 *
	 * @param stream The input stream containing the data in json syntax.
	 * @throw ::cereal::Exception if the given @p stream cannot be parsed
	 * by json parser, e.g. if syntax is wrong.
	 */
	json_file_setting_facade(std::istream& stream)
		: archive(stream)
	{
	}

	template<class data_t, class setter_t>
	void register_setting(
			setting_id id,
			data_t initial_v,
			setter_t setter) //todo add constraint
	{
		auto value = initial_v;
		try
		{
			//tries to read value from json parser.
			//the value remains unchanged if an error occurs.
			archive(cereal::make_nvp(id.key, value));
		}
		catch(const cereal::Exception& ex)
		{
			std::cerr << "json_file_setting_facade.register_setting():"
					" '"	<< ex.what() << "'" << std::endl;
		}
		setter(value);
	}
<commit_msg>make exception message more usable by hinting for probable cause of exception in jsonfile_setting_backend.hpp<commit_after>#ifndef SRC_SETTINGS_JSONFILE_SETTING_BACKEND_HPP_
#define SRC_SETTINGS_JSONFILE_SETTING_BACKEND_HPP_

#include <settings/settings.hpp>
#include <cereal/archives/json.hpp>

namespace fc
{

class json_file_setting_facade
{
public:
	typedef cereal::JSONInputArchive json_archive;

	/**
	 * @brief Creates a setting facade that reads values from
	 * stream using json format.
	 *
	 * @param stream The input stream containing the data in json syntax.
	 * @throw ::cereal::Exception if the given @p stream cannot be parsed
	 * by json parser, e.g. if syntax is wrong.
	 */
	json_file_setting_facade(std::istream& stream)
		try : archive(stream)
	{
	}
	catch (const ::cereal::Exception& ex)
	{
		throw ::cereal::Exception(std::string(ex.what())
				+ ". you should check for json syntax errors.");
	}

	template<class data_t, class setter_t>
	void register_setting(
			setting_id id,
			data_t initial_v,
			setter_t setter) //todo add constraint
	{
		auto value = initial_v;
		try
		{
			//tries to read value from json parser.
			//the value remains unchanged if an error occurs.
			archive(cereal::make_nvp(id.key, value));
		}
		catch(const cereal::Exception& ex)
		{
			std::cerr << "json_file_setting_facade.register_setting():"
					" '"	<< ex.what() << "'" << std::endl;
		}
		setter(value);
	}

{'fraction_non_alphanumeric': 0.10759737755495564, 'fraction_numerical': 0.0, 'mean_word_length': 4.198396793587174, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 9, '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': '5702502', 'n_tokens_mistral': 960, 'n_tokens_neox': 866, 'n_words': 239}