Skip to content

Commit 119a689

Browse files
safer database abstraction
1 parent cd3d153 commit 119a689

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/database.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ namespace db {
242242
exit(2);
243243
}
244244
#ifdef DPP_CORO
245-
std::thread([]() {
245+
std::thread([&bot]() {
246246
dpp::utility::set_thread_name("sql/coro");
247247
while (true) {
248248
cached_query_results qr;
@@ -260,7 +260,12 @@ namespace db {
260260
if (!qr.format.empty()) {
261261
auto results = query(qr.format, qr.parameters);
262262
if (qr.callback) {
263-
qr.callback(results);
263+
try {
264+
qr.callback(results);
265+
}
266+
catch (const std::exception& e) {
267+
bot.log(dpp::ll_warning, "Exception in SQL query callback: " + std::string(e.what()));
268+
}
264269
}
265270
}
266271
}
@@ -549,7 +554,11 @@ namespace db {
549554
thisrow[a] = b;
550555
s_field_count++;
551556
}
552-
rv.emplace_back(thisrow);
557+
if (!thisrow.empty()) {
558+
rv.emplace_back(thisrow);
559+
} else {
560+
log_error(format, "DB: Spurious empty fieldset");
561+
}
553562
}
554563
}
555564
}

0 commit comments

Comments
 (0)