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() {
CURLcode result = curl_easy_perform(this->m_ctx);
if (result != CURLE_OK)
log::error("Net request failed with error {0}: '{1}'", u32(result), curl_easy_strerror(result));
if (result != CURLE_OK){
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;
curl_easy_getinfo(this->m_ctx, CURLINFO_RESPONSE_CODE, &responseCode);

View File

@ -51,8 +51,12 @@ namespace hex::init {
this->m_currTaskName = name;
}
auto startTime = std::chrono::high_resolution_clock::now();
if (!task())
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++;
@ -119,7 +123,7 @@ namespace hex::init {
#endif
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();

View File

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

View File

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