Skip to content

Commit

Permalink
fix: catch exceptions found in user reported stacktraces
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Nov 9, 2024
1 parent 0b4b79c commit a5f56e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/core/src/platforms/all/helpers/helpers/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(my_logger, my_logger_mt) {
*/
template <typename... Args>
inline void log(severity_level lvl, fmt::format_string<Args...> format_str, Args &&...args) {
auto msg = fmt::format(format_str, std::forward<Args>(args)...);
BOOST_LOG_SEV(my_logger::get(), lvl) << msg;
try {
auto msg = fmt::format(format_str, std::forward<Args>(args)...);
BOOST_LOG_SEV(my_logger::get(), lvl) << msg;
} catch (const std::exception &e) {
std::cout << "Failed to format log message: " << e.what();
}
}

inline logs::severity_level parse_level(const std::string &level) {
Expand Down
4 changes: 3 additions & 1 deletion src/moonlight-protocol/crypto/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <iostream>
#include <openssl/err.h>
#include <ostream>
#include <stdexcept>
#include <string>

void handle_openssl_error(const std::string &msg) {
ERR_print_errors_fp(stderr);
throw std::runtime_error(msg);
std::cout << msg << std::endl;
}

std::string uc_to_str(unsigned char *uc, int len) {
Expand Down
4 changes: 2 additions & 2 deletions src/moonlight-server/control/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ bool encrypt_and_send(std::string_view payload,
std::size_t session_id) {
auto clients = connected_clients.load();
auto enet_peer = clients->find(session_id);
if (enet_peer == nullptr) {
logs::log(logs::debug, "[ENET] Unable to find enet client {}", session_id);
if (!enet_peer || payload == nullptr || aes_key == nullptr) {
logs::log(logs::debug, "[ENET] Unable to send encrypted packed {}", session_id);
return false;
} else {
auto encrypted = control::encrypt_packet(aes_key, 0, payload); // TODO: seq?
Expand Down

0 comments on commit a5f56e2

Please sign in to comment.