1
0
mirror of synced 2024-11-24 15:50:16 +01:00

sys: Improve various error messages (#789)

* Tell the user the net request which failed

* Show signal name

* Print execution time of startup tasks

* replace NULL with nullptr

* change wording for task logs

* Remove '..' from task name

* remove using namespace chrono
This commit is contained in:
iTrooz_ 2022-10-20 08:28:29 +02:00 committed by GitHub
parent 05e8e53451
commit f3b0971d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 16 deletions

View File

@ -120,8 +120,11 @@ namespace hex {
std::optional<i32> Net::execute() { std::optional<i32> Net::execute() {
CURLcode result = curl_easy_perform(this->m_ctx); CURLcode result = curl_easy_perform(this->m_ctx);
if (result != CURLE_OK) if (result != CURLE_OK){
log::error("Net request failed with error {0}: '{1}'", u32(result), curl_easy_strerror(result)); char *url = nullptr;
curl_easy_getinfo(this->m_ctx, CURLINFO_EFFECTIVE_URL, &url);
log::error("Net request '{0}' failed with error {1}: '{2}'", url, u32(result), curl_easy_strerror(result));
}
long responseCode = 0; long responseCode = 0;
curl_easy_getinfo(this->m_ctx, CURLINFO_RESPONSE_CODE, &responseCode); curl_easy_getinfo(this->m_ctx, CURLINFO_RESPONSE_CODE, &responseCode);

View File

@ -51,8 +51,12 @@ namespace hex::init {
this->m_currTaskName = name; this->m_currTaskName = name;
} }
auto startTime = std::chrono::high_resolution_clock::now();
if (!task()) if (!task())
status = false; status = false;
auto endTime = std::chrono::high_resolution_clock::now();
log::info("Task '{}' finished in {} ms", name, std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime).count());
tasksCompleted++; tasksCompleted++;
@ -119,7 +123,7 @@ namespace hex::init {
#endif #endif
drawList->AddRectFilled(ImVec2(0, splashTexture.getSize().y - 5) * scale, ImVec2(splashTexture.getSize().x * this->m_progress, splashTexture.getSize().y) * scale, 0xFFFFFFFF); drawList->AddRectFilled(ImVec2(0, splashTexture.getSize().y - 5) * scale, ImVec2(splashTexture.getSize().x * this->m_progress, splashTexture.getSize().y) * scale, 0xFFFFFFFF);
drawList->AddText(ImVec2(15, splashTexture.getSize().y - 25) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("[{}] {}", "|/-\\"[ImU32(ImGui::GetTime() * 15) % 4], this->m_currTaskName).c_str()); drawList->AddText(ImVec2(15, splashTexture.getSize().y - 25) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("[{}] {}...", "|/-\\"[ImU32(ImGui::GetTime() * 15) % 4], this->m_currTaskName).c_str());
} }
ImGui::Render(); ImGui::Render();

View File

@ -312,12 +312,12 @@ namespace hex::init {
std::vector<Task> getInitTasks() { std::vector<Task> getInitTasks() {
return { return {
{ "Creating directories...", createDirectories, false }, { "Creating directories", createDirectories, false },
{ "Loading settings...", loadSettings, false }, { "Loading settings", loadSettings, false },
{ "Loading plugins...", loadPlugins, false }, { "Loading plugins", loadPlugins, false },
{ "Checking for updates...", checkForUpdates, true }, { "Checking for updates", checkForUpdates, true },
{ "Downloading information...", downloadInformation, true }, { "Downloading information", downloadInformation, true },
{ "Loading fonts...", loadFonts, true }, { "Loading fonts", loadFonts, true },
}; };
} }

View File

@ -69,8 +69,8 @@ namespace hex {
buf->append("\n"); buf->append("\n");
} }
static void signalHandler(int signalNumber) { static void signalHandler(int signalNumber, std::string signalName) {
log::fatal("Terminating with signal {}", signalNumber); log::fatal("Terminating with signal '{}' ({})", signalName, signalNumber);
EventManager::post<EventAbnormalTermination>(signalNumber); EventManager::post<EventAbnormalTermination>(signalNumber);
@ -155,11 +155,16 @@ namespace hex {
this->m_popupsToOpen.push_back(name); this->m_popupsToOpen.push_back(name);
}); });
std::signal(SIGSEGV, signalHandler); #define HANDLE_SIGNAL(name) \
std::signal(SIGILL, signalHandler); std::signal(name, [](int signalNumber){ \
std::signal(SIGABRT, signalHandler); signalHandler(signalNumber, #name); \
std::signal(SIGFPE, signalHandler); });
std::set_terminate([]{ signalHandler(SIGABRT); }); HANDLE_SIGNAL(SIGSEGV)
HANDLE_SIGNAL(SIGILL)
HANDLE_SIGNAL(SIGABRT)
HANDLE_SIGNAL(SIGFPE)
#undef HANDLE_SIGNAL
std::set_terminate([]{ signalHandler(SIGABRT, "Unhandled C++ exception"); });
auto logoData = romfs::get("logo.png"); auto logoData = romfs::get("logo.png");
this->m_logoTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(logoData.data()), logoData.size()); this->m_logoTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(logoData.data()), logoData.size());