Skip to content

Add error dialog for critical errors on Windows#54836

Merged
topolarity merged 3 commits intoJuliaLang:masterfrom
topolarity:ct/windows-alert
Sep 22, 2025
Merged

Add error dialog for critical errors on Windows#54836
topolarity merged 3 commits intoJuliaLang:masterfrom
topolarity:ct/windows-alert

Conversation

@topolarity
Copy link
Copy Markdown
Member

@topolarity topolarity commented Jun 17, 2024

This change adds a small dialog for fatal errors on Windows:

with a corresponding entry in the Application log (in Event Viewer)

This is intended primarily for users of PackageCompiler.jl, who might be using Julia in a GUI application.

If a Julia-compiled library fails in a GUI application, users currently have no good way to know why/how their application crashed if, e.g., an exception was accidentally left unhandled in their Julia code.

Depends on #54835

TODO: Should this be a jl_options flag to determine whether to show the GUI? Should we log to the event log unconditionally? Is there any way that we can automatically detect whether stderr is connected to a terminal and user-visible?

@giordano giordano added system:windows Affects only Windows error handling Handling of exceptions by Julia or the user labels Jun 17, 2024
@topolarity topolarity force-pushed the ct/windows-alert branch 3 times, most recently from 7768244 to ca4254f Compare June 17, 2024 21:00
Comment thread src/signals-win.c Outdated
event_source, EVENTLOG_ERROR_TYPE, /* category */ 0, /* event_id */ (DWORD)0xE0000000L,
/* user_sid */ NULL, /* n_strings */ 1, /* data_size */ 0, strings, /* data */ NULL
);
MessageBoxW(NULL, /* message */ L"error: libjulia received a fatal signal.\n\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know very little about Windows, so my apologies if these questions are dumb, but: 1. Is this call async, or does it block?
2. Is this really safe to call here? In particular,
3. I am slightly worried about situations I experienced in an entirely different context were broadly similar code could lead to hundreds of dialog boxes spamming a user (when code that launched a ton of subprocesses to process data had them all fail simultaneously -- e.g. because a network connection dropped).

Anyway, none of this is meant as argument against this PR (which to me, as a non-Windows user, seems quite useful). Feel free to ignore me :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 1: it blocks the thread.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a151cf3 added a jl_options guard

It's disabled by default now, but will be enabled by PackageCompiler when exporting Julia-based libraries - hopefully that resolves some of the concern. These are "critical" errors, so in some sense they should never happen (although in practice aggressive Ctrl-C at the REPL makes them happen quite a bit, so it's good that we don't alert in that case)

@davidanthoff
Copy link
Copy Markdown
Contributor

Probably also needs to detect scenarios where no windows desktop is present? SSH, PowerShell remoting, running as a service etc.

Somehow making the dialog box optional seems like a good idea to me.

Comment thread src/signals-win.c Outdated
Comment thread src/support/ios.c Outdated
Comment thread src/signals-win.c Outdated
Copy link
Copy Markdown
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, I think this should work okay

@vtjnash vtjnash closed this Sep 17, 2025
@DilumAluthge
Copy link
Copy Markdown
Member

Was this closed intentionally?

@DilumAluthge DilumAluthge reopened this Sep 18, 2025
@topolarity topolarity force-pushed the ct/more-fprint branch 2 times, most recently from 377554f to d4137f1 Compare September 18, 2025 20:16
@topolarity
Copy link
Copy Markdown
Member Author

Was this closed intentionally?

It was, but #54835 has since been re-opened

I'll be re-visiting this soon since "Julia as a library" scenarios on Windows are becoming relevant soon

topolarity added a commit that referenced this pull request Sep 19, 2025
This adds/changes a number of `fprint_*` variants to internal debug
functions:
  - rename + new `ios_t *` argument:
    - `jl_critical_error` -> `jl_fprint_critical_error`
    - `jl_print_native_codeloc` -> `jl_fprint_native_codeloc`
    - `jl_print_bt_entry_codeloc` -> `jl_fprint_bt_entry_codeloc`
    - `jl_gc_debug_print_status` -> `jl_gc_debug_fprint_status`
- `jl_gc_debug_critical_error` -> `jl_gc_debug_fprint_critical_error`
 - new `fprint_*` variants:
    - `jl_safe_fprintf`
    - `jl_safe_static_show`
    - `jl_fprint_backtrace(t)`

Note that care needs to be taken w.r.t. what `ios_t *` value is passed
into these functions from within a signal handler on Unix. Memory
allocation is not async-signal-safe, so the ios_t needs to wrap a raw
`fd_t` handle.

Immediate motivation is #54836
@topolarity topolarity deleted the branch JuliaLang:master September 19, 2025 13:06
@topolarity topolarity closed this Sep 19, 2025
@topolarity topolarity reopened this Sep 19, 2025
@topolarity topolarity changed the base branch from ct/more-fprint to master September 19, 2025 13:09
@topolarity topolarity force-pushed the ct/windows-alert branch 2 times, most recently from 802487c to a151cf3 Compare September 19, 2025 13:33
Comment thread src/task.c
@topolarity topolarity added the merge me PR is reviewed. Merge when all tests are passing label Sep 19, 2025
@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Sep 20, 2025

build failure looks related

C:/workdir/src/support/ios.c:995:5: error: implicit declaration of function 'uv_wtf8_to_utf16' [-Wimplicit-function-declaration]
2025-09-19 20:40:54 EDT
  995 |     uv_wtf8_to_utf16(str, wstr, wlen);

@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Sep 20, 2025
This can be very useful when your Julia-built library hits an unexpected
exception and causes a GUI-based application to crash with no error
message.
This is disabled by default, but it can be enabled by downstream
applications (in particular, by JuliaC.jl / PackageCompiler) so
Windows users with a Julia library in a pure GUI application will
get a useful error message for a crash.
@topolarity
Copy link
Copy Markdown
Member Author

build failure looks related

C:/workdir/src/support/ios.c:995:5: error: implicit declaration of function 'uv_wtf8_to_utf16' [-Wimplicit-function-declaration]
2025-09-19 20:40:54 EDT
  995 |     uv_wtf8_to_utf16(str, wstr, wlen);

Fixed.

Do we have not have -Werror=implicit-function-declaration configured?

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Sep 20, 2025

IIRC, Werror is currently only enabled for linux builders in buildkite, since nobody has thought to enable it for others

@topolarity topolarity merged commit b83b35c into JuliaLang:master Sep 22, 2025
7 checks passed
@giordano
Copy link
Copy Markdown
Member

IIRC, Werror is currently only enabled for linux builders in buildkite, since nobody has thought to enable it for others

It's actually only missing for Windows (should be enabled already for all Unices platforms) because nobody went through all the warnings issued when targeting that platform, which is what Cody has now been working on starting with #59634

xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
This adds/changes a number of `fprint_*` variants to internal debug
functions:
  - rename + new `ios_t *` argument:
    - `jl_critical_error` -> `jl_fprint_critical_error`
    - `jl_print_native_codeloc` -> `jl_fprint_native_codeloc`
    - `jl_print_bt_entry_codeloc` -> `jl_fprint_bt_entry_codeloc`
    - `jl_gc_debug_print_status` -> `jl_gc_debug_fprint_status`
- `jl_gc_debug_critical_error` -> `jl_gc_debug_fprint_critical_error`
 - new `fprint_*` variants:
    - `jl_safe_fprintf`
    - `jl_safe_static_show`
    - `jl_fprint_backtrace(t)`

Note that care needs to be taken w.r.t. what `ios_t *` value is passed
into these functions from within a signal handler on Unix. Memory
allocation is not async-signal-safe, so the ios_t needs to wrap a raw
`fd_t` handle.

Immediate motivation is JuliaLang#54836
xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
This change adds a small dialog (disabled by default) for fatal errors on Windows
with a corresponding entry in the `Application` log (in Event Viewer, enabled by default)

This is intended primarily for users of PackageCompiler.jl, who might be
using Julia in a GUI application.

If a Julia-compiled library fails in a GUI application, users currently
have no good way to know why/how their application crashed if, e.g., an
exception was accidentally left unhandled in their Julia code.

Depends on JuliaLang#54835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error handling Handling of exceptions by Julia or the user system:windows Affects only Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants