diff --git a/src/addon/manager.cpp b/src/addon/manager.cpp index e90eea5dfd1..1158862f4a6 100644 --- a/src/addon/manager.cpp +++ b/src/addon/manager.cpp @@ -119,7 +119,7 @@ void get_addon_install_info(const std::string& addon_name, config& cfg) } catch(const config::error& e) { ERR_CFG << "Failed to read add-on installation information for '" << addon_name << "' from " << info_path << ":\n" - << e.message << '\n'; + << e.message << std::endl; } } diff --git a/src/config_cache.cpp b/src/config_cache.cpp index b6d101b92e4..32d823dcc22 100644 --- a/src/config_cache.cpp +++ b/src/config_cache.cpp @@ -57,7 +57,7 @@ namespace game_config { struct output { void operator()(const preproc_map::value_type& def) { - DBG_CACHE << "key: " << def.first << " " << def.second << "\n"; + DBG_CACHE << "key: " << def.first << " " << def.second << std::endl; } }; const preproc_map& config_cache::get_preproc_map() const @@ -67,7 +67,7 @@ namespace game_config { void config_cache::clear_defines() { - LOG_CACHE << "Clearing defines map!\n"; + LOG_CACHE << "Clearing defines map!" << std::endl; defines_map_.clear(); // set-up default defines map @@ -146,9 +146,13 @@ namespace game_config { void config_cache::read_configs(const std::string& path, config& cfg, preproc_map& defines_map) { - //read the file and then write to the cache - scoped_istream stream = preprocess_file(path, &defines_map); - read(cfg, *stream); + try { + //read the file and then write to the cache + scoped_istream stream = preprocess_file(path, &defines_map); + read(cfg, *stream); + } catch (config::error & e) { + ERR_CACHE << "error parsing configs in '" << path << "', got config::error\n" << e.message << std::endl; + } } void config_cache::read_cache(const std::string& path, config& cfg) diff --git a/src/editor/map/map_context.cpp b/src/editor/map/map_context.cpp index f60e9e84171..2f8fac0b5e4 100644 --- a/src/editor/map/map_context.cpp +++ b/src/editor/map/map_context.cpp @@ -153,12 +153,16 @@ map_context::map_context(const config& game_config, const std::string& filename, boost::regex rexpression_scenario("\\[scenario\\]|\\[test\\]|\\[multiplayer\\]"); if (!boost::regex_search(file_string, rexpression_scenario)) { - LOG_ED << "Loading generated scenario file\n"; + LOG_ED << "Loading generated scenario file" << std::endl; // 4.0 editor generated scenario - load_scenario(game_config); + try { + load_scenario(game_config); + } catch (config::error & e) { + throw editor_map_load_exception("load_scenario", e.message); //we already caught and rethrew this exception in load_scenario + } return; } else { - LOG_ED << "Loading embedded map file\n"; + LOG_ED << "Loading embedded map file" << std::endl; embedded_ = true; pure_map_ = true; map_ = editor_map::from_string(game_config, map_data); @@ -168,7 +172,7 @@ map_context::map_context(const config& game_config, const std::string& filename, // 3.0 Macro referenced pure map const std::string& macro_argument = matched_macro[1]; - LOG_ED << "Map looks like a scenario, trying {" << macro_argument << "}\n"; + LOG_ED << "Map looks like a scenario, trying {" << macro_argument << "}" << std::endl; std::string new_filename = get_wml_location(macro_argument, directory_name(macro_argument)); if (new_filename.empty()) { @@ -177,7 +181,7 @@ map_context::map_context(const config& game_config, const std::string& filename, + std::string("\n") + macro_argument; throw editor_map_load_exception(filename, message); } - LOG_ED << "New filename is: " << new_filename << "\n"; + LOG_ED << "New filename is: " << new_filename << std::endl; filename_ = new_filename; file_string = read_file(filename_); map_ = editor_map::from_string(game_config, file_string); @@ -252,7 +256,13 @@ void map_context::replace_local_schedule(const std::vector& schedul void map_context::load_scenario(const config& game_config) { config scenario; - read(scenario, *(preprocess_file(filename_))); + + try { + read(scenario, *(preprocess_file(filename_))); + } catch (config::error & e) { + LOG_ED << "Caught a config error while parsing file: '" << filename_ << "'\n" << e.message << std::endl; + throw e; + } scenario_id_ = scenario["id"].str(); scenario_name_ = scenario["name"].str(); @@ -560,7 +570,7 @@ void map_context::set_map(const editor_map& map) void map_context::perform_action(const editor_action& action) { LOG_ED << "Performing action " << action.get_id() << ": " << action.get_name() - << ", actions count is " << action.get_instance_count() << "\n"; + << ", actions count is " << action.get_instance_count() << std::endl; editor_action* undo = action.perform(*this); if (actions_since_save_ < 0) { //set to a value that will make it impossible to get to zero, as at this point @@ -576,7 +586,7 @@ void map_context::perform_action(const editor_action& action) void map_context::perform_partial_action(const editor_action& action) { LOG_ED << "Performing (partial) action " << action.get_id() << ": " << action.get_name() - << ", actions count is " << action.get_instance_count() << "\n"; + << ", actions count is " << action.get_instance_count() << std::endl; if (!can_undo()) { throw editor_logic_exception("Empty undo stack in perform_partial_action()"); } @@ -632,26 +642,26 @@ const editor_action* map_context::last_redo_action() const void map_context::undo() { - LOG_ED << "undo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << "\n"; + LOG_ED << "undo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl; if (can_undo()) { perform_action_between_stacks(undo_stack_, redo_stack_); actions_since_save_--; } else { WRN_ED << "undo() called with an empty undo stack" << std::endl; } - LOG_ED << "undo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << "\n"; + LOG_ED << "undo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl; } void map_context::redo() { - LOG_ED << "redo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << "\n"; + LOG_ED << "redo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl; if (can_redo()) { perform_action_between_stacks(redo_stack_, undo_stack_); actions_since_save_++; } else { WRN_ED << "redo() called with an empty redo stack" << std::endl; } - LOG_ED << "redo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << "\n"; + LOG_ED << "redo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl; } void map_context::partial_undo() diff --git a/src/game.cpp b/src/game.cpp index ba542c251aa..0538ec6b4b9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -154,8 +154,13 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts) std::cerr << SDL_GetTicks() << " Reading cached defines from: " << file << "\n"; config cfg; - scoped_istream stream = istream_file( file ); - read( cfg, *stream ); + + try { + scoped_istream stream = istream_file( file ); + read( cfg, *stream ); + } catch (config::error & e) { + std::cerr << "Caught a config error while parsing file '" << file << "':\n" << e.message << std::endl; + } int read = 0; diff --git a/src/persist_context.cpp b/src/persist_context.cpp index 47e56d85e82..e44ca417db6 100644 --- a/src/persist_context.cpp +++ b/src/persist_context.cpp @@ -42,7 +42,7 @@ void persist_file_context::load() try { read(cfg_,*file_stream); } catch (config::error &err) { - LOG_PERSIST << err.message; + LOG_PERSIST << err.message << std::endl; } } } @@ -188,7 +188,7 @@ bool persist_file_context::save_context() { writer.write(cfg_); success = true; } catch(config::error &err) { - LOG_PERSIST << err.message; + LOG_PERSIST << err.message << std::endl; success = false; } } diff --git a/src/savegame.cpp b/src/savegame.cpp index ea74358f826..69b39f4b87a 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -224,8 +224,8 @@ private: } } catch(io_exception& e) { ERR_SAVE << "error reading save index: '" << e.what() << "'" << std::endl; - } catch(config::error&) { - ERR_SAVE << "error parsing save index config file" << std::endl; + } catch(config::error& e) { + ERR_SAVE << "error parsing save index config file:\n" << e.message << std::endl; data_.clear(); } loaded_ = true; @@ -904,7 +904,7 @@ bool savegame::save_game(CVideo* video, const std::string& filename) } else { gamestate_.classification().parent = parent; } - LOG_SAVE << "Setting parent of '" << filename_<< "' to " << gamestate_.classification().parent << "\n"; + LOG_SAVE << "Setting parent of '" << filename_<< "' to " << gamestate_.classification().parent << std::endl; write_game_to_disk(filename_); if (resources::persist != NULL) { @@ -916,13 +916,13 @@ bool savegame::save_game(CVideo* video, const std::string& filename) parent = filename_; end = SDL_GetTicks(); - LOG_SAVE << "Milliseconds to save " << filename_ << ": " << end - start << "\n"; + LOG_SAVE << "Milliseconds to save " << filename_ << ": " << end - start << std::endl; if (video != NULL && show_confirmation_) gui2::show_transient_message(*video, _("Saved"), _("The game has been saved.")); return true; } catch(game::save_game_failed& e) { - ERR_SAVE << error_message_ << e.message; + ERR_SAVE << error_message_ << e.message << std::endl; if (video != NULL){ gui2::show_error_message(*video, error_message_ + e.message); //do not bother retrying, since the user can just try to save the game again @@ -935,7 +935,7 @@ bool savegame::save_game(CVideo* video, const std::string& filename) void savegame::write_game_to_disk(const std::string& filename) { - LOG_SAVE << "savegame::save_game"; + LOG_SAVE << "savegame::save_game" << std::endl; filename_ = filename; filename_ += compression::format_extension(compress_saves_);