addon/mg: Trap config::error exceptions thrown during .pbl read

This introduces a new minimal exception object to encapsulate some
relevant information (the file path and the config::error message) so it
can be propagated to the manager UI code correctly.

This is the first step is ensuring faulty .pbl files are not reported
during connection to the add-ons server as a "network communication
error".
This commit is contained in:
Ignacio R. Morelle 2013-08-21 06:06:55 -04:00
parent d3bb951548
commit 433a245266
2 changed files with 32 additions and 2 deletions

View File

@ -90,8 +90,13 @@ bool have_addon_pbl_info(const std::string& addon_name)
void get_addon_pbl_info(const std::string& addon_name, config& cfg)
{
scoped_istream stream = istream_file(get_pbl_file_path(addon_name));
read(cfg, *stream);
const std::string& pbl_path = get_pbl_file_path(addon_name);
try {
scoped_istream stream = istream_file(pbl_path);
read(cfg, *stream);
} catch(const config::error& e) {
throw invalid_pbl_exception(pbl_path, e.message);
}
}
void set_addon_pbl_info(const std::string& addon_name, const config& cfg)

View File

@ -25,6 +25,28 @@ class version_info;
#include <vector>
#include <utility>
/**
* Exception thrown when the WML parser fails to read a .pbl file.
*/
struct invalid_pbl_exception
{
/**
* Constructor.
*
* @param pbl_path Path to the faulty .pbl file.
* @param msg An error message to display.
*/
invalid_pbl_exception(const std::string& pbl_path, const std::string& msg)
: path(pbl_path), message(msg)
{}
/** Path to the faulty .pbl file. */
const std::string path;
/** Error message to display. */
const std::string message;
};
bool remove_local_addon(const std::string& addon);
/**
@ -45,6 +67,9 @@ bool have_addon_in_vcs_tree(const std::string& addon_name);
* @param addon_name The add-on's main directory/file name.
* @param cfg A config object to store the add-on's
* properties.
*
* @exception invalid_pbl_exception If it is not possible to read the .pbl file
* (often due to invalid WML).
*/
void get_addon_pbl_info(const std::string& addon_name, class config& cfg);