Author Topic: Error logging on Windows  (Read 408 times)

0 Members and 2 Guests are viewing this topic.

Offline Forestidia86

  • Posts: 725
  • inactive
    • View Profile
Error logging on Windows
« on: April 26, 2024, 09:49:54 PM »
Due to issue #488 some errors aren't logged into log.txt, although the error would show on console/shell.

On Win the console is suppressed, so that it can happen that no error feedback is given (in case no error window appears). As a workaround piping with e.g. lix.exe 2>a.txt produces the error message in a.txt.

Offline Simon

  • Administrator
  • Posts: 3906
    • View Profile
    • Lix
Re: Error logging on Windows
« Reply #1 on: April 27, 2024, 11:20:02 AM »
Right.

First, #488: Logging (user/log.txt): Exceptions during init aren't logged. This will be easy to fix. I'll fix this in the next release, Lix 0.10.23. I've already put the fix in my unstable repo's master.

Second, on Windows, years ago, the D runtime used to generate a dialog box for unrecoverable errors (exceptions/errors flying out of main). Only after clicking away that dialog box, Lix would exit. Nowadays, we don't get this dialog box anymore. I don't know why we don't get the dialog anymore.

Third, on Windows, we suppress the console. This is correct. We'll ask people to look in user/log.txt for errors. The above #488 has prevented this during initialization, it won't prevent it from Lix 0.10.23 on.



We can investigate why there is no dialog box (above "Second, on Windows ..."). Possible relation with suppressing the console? Although we have suppressed the console for years, too.

-- Simon

Offline Simon

  • Administrator
  • Posts: 3906
    • View Profile
    • Lix
Re: Error logging on Windows
« Reply #2 on: May 01, 2024, 09:15:58 PM »
We link both the 32-bit and the 64-bit executables with lld-link. These executables will try to write all exceptions flying out of main() to stderr, which is closed because we suppress the console. Therefore, we see Lix terminate seemingly without error.

When we link a test project with Optlink (instead of with lld-link) and again suppress the console, we get the desired error box for exceptions flying out of main().

Is it possible to route the uncaught exceptions to error boxes even when we link with lld-link? I've looked through lld-link's command-line switches, and none of them look related. I'll ask on the D forums these days.

-- Simon
« Last Edit: May 02, 2024, 05:42:15 AM by Simon »

Offline Simon

  • Administrator
  • Posts: 3906
    • View Profile
    • Lix
Re: Error logging on Windows
« Reply #3 on: May 05, 2024, 09:11:38 PM »
I'm asking on the D forums: Does the D runtime support generating an error box for uncaught exceptions?

I don't believe it does. We'll generate the message box by hand.

Code: [Select]
version (Windows) {
    import core.sys.windows.windows;
    const wstring messageBody = /* ... */
    MessageBoxW(null, messageBody.ptr, null, MB_ICONERROR);
}

I'll put this in the catch-all that logs uncaught exceptions, then terminates Lix. Now, every time we log an uncaught exception on Windows, we'll also display an error box.

The box doesn't know about the Allegro 5 window (= Lix's main window). You can bring the hanging Lix window into the foreground, obscuring the modal box. Possible future investigation: Pass the Allegro 5 window instead of null for the first argument to MessageBoxW() and look at how the box interacts with the Lix window.

-- Simon
« Last Edit: May 05, 2024, 09:39:27 PM by Simon »