Commit ce14593f by Maarten L. Hekkelman

improved loading resources from absolute path

better error reporting when loading dictionary
parent 1c02a451
......@@ -911,6 +911,9 @@ std::unique_ptr<std::istream> resource_pool::load(fs::path name)
if (mLocalResources.count(name.string()))
result = open(mLocalResources[name.string()]);
if (fs::exists(p, ec) and not ec)
result = open(p);
for (auto di = mDirs.begin(); not result and di != mDirs.end(); ++di)
{
auto p2 = *di / p;
......
......@@ -24,10 +24,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cif++/dictionary_parser.hpp"
#include "cif++/validate.hpp"
#include "cif++/utilities.hpp"
#include "cif++/dictionary_parser.hpp"
#include "cif++/gzio.hpp"
#include "cif++/utilities.hpp"
#include <cassert>
#include <fstream>
......@@ -401,6 +401,8 @@ void validator::report_error(const std::string &msg, bool fatal) const
const validator &validator_factory::operator[](std::string_view dictionary_name)
{
try
{
std::lock_guard lock(m_mutex);
for (auto &validator : m_validators)
......@@ -426,8 +428,6 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
}
// not found, add it
auto data = load_resource(dictionary_name);
if (not data and dictionary.extension().string() != ".dic")
......@@ -482,6 +482,13 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
}
return m_validators.back();
}
catch (const std::exception &ex)
{
std::string msg = "Error while loading dictionary ";
msg += dictionary_name;
std::throw_with_nested(std::runtime_error(msg));
}
}
void validator_factory::construct_validator(std::string_view name, std::istream &is)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment