ui: Added error popup when an exception is thrown in a task
This commit is contained in:
parent
0a115a3c03
commit
1a21627cdb
@ -32,6 +32,7 @@ namespace hex {
|
||||
[[nodiscard]] bool hadException() const;
|
||||
[[nodiscard]] bool wasInterrupted() const;
|
||||
void clearException();
|
||||
[[nodiscard]] std::string getExceptionMessage() const;
|
||||
|
||||
[[nodiscard]] const std::string &getUnlocalizedName();
|
||||
[[nodiscard]] u64 getValue() const;
|
||||
@ -42,7 +43,7 @@ namespace hex {
|
||||
private:
|
||||
void finish();
|
||||
void interruption();
|
||||
void exception();
|
||||
void exception(const char *message);
|
||||
|
||||
private:
|
||||
mutable std::mutex m_mutex;
|
||||
@ -56,6 +57,7 @@ namespace hex {
|
||||
bool m_interrupted = false;
|
||||
bool m_finished = false;
|
||||
bool m_hadException = false;
|
||||
std::string m_exceptionMessage;
|
||||
|
||||
struct TaskInterruptor { virtual ~TaskInterruptor() = default; };
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <hex/api/task.hpp>
|
||||
|
||||
#include <hex/api/localization.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -18,7 +19,11 @@ namespace hex {
|
||||
func(*this);
|
||||
} catch (const TaskInterruptor &) {
|
||||
this->interruption();
|
||||
} catch (const std::exception &e) {
|
||||
log::error("Exception in task {}: {}", this->m_unlocalizedName, e.what());
|
||||
this->exception();
|
||||
} catch (...) {
|
||||
log::error("Exception in task {}", this->m_unlocalizedName);
|
||||
this->exception();
|
||||
}
|
||||
|
||||
@ -93,6 +98,12 @@ namespace hex {
|
||||
this->m_hadException = false;
|
||||
}
|
||||
|
||||
std::string Task::getExceptionMessage() const {
|
||||
std::scoped_lock lock(this->m_mutex);
|
||||
|
||||
return this->m_exceptionMessage;
|
||||
}
|
||||
|
||||
const std::string &Task::getUnlocalizedName() {
|
||||
return this->m_unlocalizedName;
|
||||
}
|
||||
@ -117,9 +128,10 @@ namespace hex {
|
||||
this->m_interrupted = true;
|
||||
}
|
||||
|
||||
void Task::exception() {
|
||||
void Task::exception(const char *message) {
|
||||
std::scoped_lock lock(this->m_mutex);
|
||||
|
||||
this->m_exceptionMessage = message;
|
||||
this->m_hadException = true;
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,15 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Task exception popup
|
||||
for (const auto &task : TaskManager::getRunningTasks()) {
|
||||
if (task->hadException()) {
|
||||
EventManager::post<RequestShowErrorPopup>(hex::format("hex.builtin.popup.error.task_exception"_lang, LangEntry(task->getUnlocalizedName()), task->getExceptionMessage()));
|
||||
task->clearException();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addGlobalUIItems() {
|
||||
|
@ -101,6 +101,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Schreibzugriff konnte nicht erlangt werden. Datei wurde im Lesemodus geöffnet." },
|
||||
{ "hex.builtin.popup.error.open", "Öffnen der Datei fehlgeschlagen!" },
|
||||
{ "hex.builtin.popup.error.create", "Erstellen der neuen Datei fehlgeschlagen!" },
|
||||
{ "hex.builtin.popup.error.task_exception", "Fehler in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "Datei" },
|
||||
{ "hex.builtin.file.open_file", "Datei öffnen..." },
|
||||
|
@ -103,6 +103,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Couldn't get write access. File opened in read-only mode." },
|
||||
{ "hex.builtin.popup.error.open", "Failed to open file!" },
|
||||
{ "hex.builtin.popup.error.create", "Failed to create new file!" },
|
||||
{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||
|
@ -101,6 +101,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Impossibile scrivere sul File. File aperto solo in modalità lettura" },
|
||||
{ "hex.builtin.popup.error.open", "Impossibile aprire il File!" },
|
||||
{ "hex.builtin.popup.error.create", "Impossibile creare il nuovo File!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||
|
@ -101,6 +101,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "書き込み権限を取得できませんでした。ファイルが読み取り専用で開かれました。" },
|
||||
{ "hex.builtin.popup.error.open", "ファイルを開けませんでした。" },
|
||||
{ "hex.builtin.popup.error.create", "新しいファイルを作成できませんでした。" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "ファイル" },
|
||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||
|
@ -102,6 +102,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "쓰기 권한을 가져올 수 없습니다. 파일이 읽기 전용 모드로 열렸습니다." },
|
||||
{ "hex.builtin.popup.error.open", "파일을 여는데 실패했습니다!" },
|
||||
{ "hex.builtin.popup.error.create", "새 파일을 만드는데 실패했습니다!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "파일" },
|
||||
{ "hex.builtin.menu.file.create_file", "새 파일..." },
|
||||
|
@ -101,6 +101,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Não foi possível obter acesso de gravação. Arquivo aberto no modo somente leitura." },
|
||||
{ "hex.builtin.popup.error.open", "Falha ao abrir o arquivo!" },
|
||||
{ "hex.builtin.popup.error.create", "Falha ao criar um novo arquivo!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||
|
@ -101,6 +101,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "无法获得写权限,文件以只读方式打开。" },
|
||||
{ "hex.builtin.popup.error.open", "打开文件失败!" },
|
||||
{ "hex.builtin.popup.error.create", "创建新文件失败!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "文件" },
|
||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||
|
@ -101,6 +101,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "無法取得寫入權限。檔案已以唯讀模式開啟。" },
|
||||
{ "hex.builtin.popup.error.open", "無法開啟檔案!" },
|
||||
{ "hex.builtin.popup.error.create", "無法建立新檔案!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "檔案" },
|
||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||
|
Loading…
x
Reference in New Issue
Block a user