Skip to content

Commit b36bbc5

Browse files
committed
Fixed incorrect error handling for sol::state::do_file
1 parent 20487b0 commit b36bbc5

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/gui_addon_registry.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ void addon_registry::load_addon_files_(const addon& a) {
103103
for (const auto& file : a.file_list) {
104104
const std::string extension = utils::get_file_extension(file);
105105
if (extension == ".lua") {
106-
try {
107-
lua_.do_file(file);
108-
} catch (const sol::error& e) {
109-
std::string err = e.what();
106+
auto result = lua_.do_file(file);
107+
if (!result.valid()) {
108+
std::string err = result.get<sol::error>().what();
110109
gui::out << gui::error << err << std::endl;
111110
event_emitter_.fire_event("LUA_ERROR", {err});
112111
}
@@ -117,11 +116,11 @@ void addon_registry::load_addon_files_(const addon& a) {
117116

118117
std::string saved_variables_file =
119118
"saves/interface/" + a.main_directory + "/" + a.name + ".lua";
119+
120120
if (utils::file_exists(saved_variables_file)) {
121-
try {
122-
lua_.do_file(saved_variables_file);
123-
} catch (const sol::error& e) {
124-
std::string err = e.what();
121+
auto result = lua_.do_file(saved_variables_file);
122+
if (!result.valid()) {
123+
std::string err = result.get<sol::error>().what();
125124
gui::out << gui::error << err << std::endl;
126125
event_emitter_.fire_event("LUA_ERROR", {err});
127126
}

src/gui_addon_registry_parser.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ void addon_registry::parse_layout_file_(const std::string& file_name, const addo
242242
std::string script_file =
243243
add_on.directory + "/" + node.get_attribute_value<std::string>("file");
244244

245-
try {
246-
lua_.do_file(script_file);
247-
} catch (const sol::error& e) {
248-
std::string err = e.what();
245+
auto result = lua_.do_file(script_file);
246+
if (!result.valid()) {
247+
std::string err = result.get<sol::error>().what();
249248
gui::out << gui::error << err << std::endl;
250249
event_emitter_.fire_event("LUA_ERROR", {err});
251250
}

0 commit comments

Comments
 (0)