+#include <cassert>
#include <fstream>
#include <unordered_set>
#include <unordered_map>
BaseLua4::BaseLua4() {
}
-int BaseLua4::loadFile(const std::string& fname)
+void BaseLua4::loadFile(const std::string& fname)
{
- int ret = 0;
std::ifstream ifs(fname);
if (!ifs) {
- ret = errno;
- SLOG(g_log << Logger::Error << "Unable to read configuration file from '" << fname << "': " << stringerror(ret) << endl,
- g_slog->withName("lua")->error(Logr::Error, ret, "Unable to read configuration file", "file", Logging::Loggable(fname)));
- return ret;
+ auto ret = errno;
+ auto msg = stringerror(ret);
+ SLOG(g_log << Logger::Error << "Unable to read configuration file from '" << fname << "': " << msg << endl,
+ g_slog->withName("lua")->error(Logr::Error, ret, "Unable to read configuration file", "file", Logging::Loggable(fname), "msg", Logging::Loggable(msg)));
+ throw std::runtime_error(msg);
}
loadStream(ifs);
- return 0;
};
void BaseLua4::loadString(const std::string &script) {
public:
BaseLua4();
- int loadFile(const std::string &fname);
+ void loadFile(const std::string &fname);
void loadString(const std::string &script);
void loadStream(std::istream &is);
virtual ~BaseLua4(); // this is so unique_ptr works with an incomplete type
}
else {
t_pdl = std::make_shared<RecursorLua4>();
- int err = t_pdl->loadFile(fname);
- if (err != 0) {
- string msg = std::to_string(RecThreadInfo::id()) + " Retaining current script, could not read '" + fname + "': " + stringerror(err);
+ try {
+ t_pdl->loadFile(fname);
+ }
+ catch (std::runtime_error& ex) {
+ string msg = std::to_string(RecThreadInfo::id()) + " Retaining current script, could not read '" + fname + "': " + ex.what();
g_log << Logger::Error << msg << endl;
return new RecursorControlChannel::Answer{1, msg + "\n"};
}