From 70a0fbab02ddfd08310999da78e5d9e56fdd652b Mon Sep 17 00:00:00 2001 From: "Lin, Yong Xiang" Date: Wed, 18 Sep 2024 09:22:43 +0800 Subject: [PATCH] Restore Catch Exception Logic (#424) In any case, we should not crash at the user end This commit reverts the previous FileException only error handling And add runtime error dump to let users know that they should report to developers --- source/creator/package.d | 13 +++++++++---- source/creator/utils/crashdump.d | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/creator/package.d b/source/creator/package.d index 0c06c4323..16622b1b2 100644 --- a/source/creator/package.d +++ b/source/creator/package.d @@ -231,7 +231,6 @@ bool incOpenProject(string path) { */ bool incOpenProject(string mainPath, string backupPath) { import std.path : setExtension, baseName; - import std.file : FileException; incClearImguiData(); @@ -244,9 +243,15 @@ bool incOpenProject(string mainPath, string backupPath) { } else { puppet = inLoadPuppet!ExPuppet(mainPath); } - } catch (FileException ex) { - // Also handle NFS or I/O errors - incDialog(__("Error"), ex.msg); + } catch (Exception ex) { + // for user, we should show a dialog and dump the thrown stack + import std.file : write; + import creator.utils.crashdump; + string path = genCrashDumpPath("inochi-creator-runtime-error"); + write(path, genCrashDump(ex)); + + // show dialog + incDialog(__("Error"), ex.msg ~ "\n\n" ~ _("Please report this file to the developers:\n\n%s").format(path)); return false; } diff --git a/source/creator/utils/crashdump.d b/source/creator/utils/crashdump.d index 9138dad51..352608d0f 100644 --- a/source/creator/utils/crashdump.d +++ b/source/creator/utils/crashdump.d @@ -53,12 +53,15 @@ string getCrashDumpDir() { else return expandTilde("~"); } - +string genCrashDumpPath(string filename) { + import std.datetime; + return buildPath(getCrashDumpDir(), filename ~ "-" ~ Clock.currTime.toISOString() ~ ".txt"); +} void crashdump(T...)(Throwable throwable, T state) { // Write crash dump to disk - write(buildPath(getCrashDumpDir(), "inochi-creator-crashdump.txt"), genCrashDump!T(throwable, state)); + write(genCrashDumpPath("inochi-creator-crashdump"), genCrashDump!T(throwable, state)); // Use appropriate system method to notify user where crash dump is. version(OSX) writeln(_("\n\n\n=== Inochi Creator has crashed ===\nPlease send us the inochi-creator-crashdump.txt file in ~/Library/Logs\nAttach the file as a git issue @ https://github.com/Inochi2D/inochi-creator/issues"));