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) ...@@ -911,6 +911,9 @@ std::unique_ptr<std::istream> resource_pool::load(fs::path name)
if (mLocalResources.count(name.string())) if (mLocalResources.count(name.string()))
result = open(mLocalResources[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) for (auto di = mDirs.begin(); not result and di != mDirs.end(); ++di)
{ {
auto p2 = *di / p; auto p2 = *di / p;
......
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "cif++/dictionary_parser.hpp"
#include "cif++/validate.hpp" #include "cif++/validate.hpp"
#include "cif++/utilities.hpp" #include "cif++/dictionary_parser.hpp"
#include "cif++/gzio.hpp" #include "cif++/gzio.hpp"
#include "cif++/utilities.hpp"
#include <cassert> #include <cassert>
#include <fstream> #include <fstream>
...@@ -401,6 +401,8 @@ void validator::report_error(const std::string &msg, bool fatal) const ...@@ -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) const validator &validator_factory::operator[](std::string_view dictionary_name)
{ {
try
{
std::lock_guard lock(m_mutex); std::lock_guard lock(m_mutex);
for (auto &validator : m_validators) for (auto &validator : m_validators)
...@@ -426,8 +428,6 @@ const validator &validator_factory::operator[](std::string_view dictionary_name) ...@@ -426,8 +428,6 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
} }
// not found, add it // not found, add it
auto data = load_resource(dictionary_name); auto data = load_resource(dictionary_name);
if (not data and dictionary.extension().string() != ".dic") if (not data and dictionary.extension().string() != ".dic")
...@@ -482,6 +482,13 @@ const validator &validator_factory::operator[](std::string_view dictionary_name) ...@@ -482,6 +482,13 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
} }
return m_validators.back(); 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) 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