Skip to content

Commit

Permalink
Only show the error message box for interactive Windows processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Apr 2, 2024
1 parent be69b76 commit 7ed58f6
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions source/vibe/core/task.d
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,31 @@ final package class TaskFiber : Fiber {
import core.stdc.stdlib : abort;
import core.memory : GC;
try {
// On Windows, also show a message box to the user if the
// application is interactive and does not have a console
// associated
version (Windows) {
import core.sys.windows.windows : MessageBoxA, MB_ICONERROR, GetConsoleWindow;
import core.sys.windows.windows : GetConsoleWindow, GetProcessWindowStation,
GetUserObjectInformationA, MessageBoxA, MB_ICONERROR, UOI_FLAGS,
USEROBJECTFLAGS, WSF_VISIBLE;
import std.format : formattedWrite;
import vibe.container.internal.appender : BufferOverflowMode, FixedAppender;

if (!GetConsoleWindow()) {
FixedAppender!(char[], 2048, BufferOverflowMode.ignore) msg = void;
msg.formattedWrite("%s: %s\r\n\r\n", th.classinfo.name, th.msg);
foreach (ln; th.info)
msg.formattedWrite("%s\r\n", ln);
msg.put('\0');
msg.data[msg.data.length-1] = '\0';
MessageBoxA(null, msg.data.ptr, "FATAL: Uncaught exception in task fiber", MB_ICONERROR);
USEROBJECTFLAGS wsf;
GetUserObjectInformationA(GetProcessWindowStation(), UOI_FLAGS, &wsf, wsf.sizeof, null);
if (wsf.dwFlags & WSF_VISIBLE) {
FixedAppender!(char[], 2048, BufferOverflowMode.ignore) msg = void;
msg.formattedWrite("%s: %s\r\n\r\n", th.classinfo.name, th.msg);
foreach (ln; th.info)
msg.formattedWrite("%s\r\n", ln);
msg.put('\0');
msg.data[msg.data.length-1] = '\0';
MessageBoxA(null, msg.data.ptr, "FATAL: Uncaught exception in task fiber", MB_ICONERROR);
}
}
}

if (GC.inFinalizer) {
stderr.writeln("TaskFiber getting terminated due to an uncaught ", th.classinfo.name, ": ", th.msg);
foreach (ln; th.info) stderr.writeln(ln);
Expand Down

0 comments on commit 7ed58f6

Please sign in to comment.