On catching fatal error, prompt to save the log and report

This commit is contained in:
2025-03-06 17:07:14 -06:00
committed by Celtic Minstrel
parent 823fb8904d
commit 4cc6d7efb9
2 changed files with 35 additions and 3 deletions

View File

@@ -199,6 +199,17 @@ eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
short menuChoiceId=-1;
#endif
static void handleFatalError(std::string what) {
showFatalError(what);
if(recording){
record_action("error", what);
extern fs::path log_file;
if(log_file.empty() && cChoiceDlog("ask-save-replay", {"yes", "no"}).show() == "yes") {
save_replay_log();
}
}
}
int main(int argc, char* argv[]) {
#if 0
void debug_oldstructs();
@@ -231,13 +242,13 @@ int main(int argc, char* argv[]) {
close_program();
return 0;
} catch(std::exception& x) {
showFatalError(x.what());
handleFatalError(x.what());
throw;
} catch(std::string& x) {
showFatalError(x);
handleFatalError(x);
throw;
} catch(...) {
showFatalError("An unknown error occurred!");
handleFatalError("An unknown error occurred!");
throw;
}
}
@@ -941,6 +952,8 @@ static void replay_action(Element& action) {
preview_every_dialog_xml();
}else if(t == "clear_trapped_monst"){
clear_trapped_monst();
}else if(t == "error"){
// The error is recorded for debugging only. It should be triggered by replaying the actions.
}else if(t == "advance_time"){
// This is bad regardless of strictness, because visual changes may have occurred which won't get redrawn/reprinted
throw std::string { "Replay system internal error! advance_time() was supposed to be called by the last action, but wasn't: " } + _last_action_type;