On WinForms, if `startup` throws an exception, it is not logged, and the app continues in an unusable state
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 40
Description
### Describe the bug
The following 2 scenarios are both OK:
* If an app throws an exception before calling `startup` (e.g. from a failed `import`), then it's shown in a dialog, and also written to a log file. After closing the dialog, the process exits.
* If an app throws an exception in an event handler, then the process continues to run, but the traceback is still written to the log file.
However, if `startup` throws an exception, it is not displayed or written anywhere, unless the app happens to be connected to a console. The process continues to run, but it has no window, so it can't easily be terminated, or even uninstalled.
`print` calls immediately before the exception *do* get written to the log file, both for stdout and stderr. So this is probably an issue with Toga rather than Briefcase.
### Steps to reproduce
Edit `startup` to throw an exception before displaying the main window.
Run `briefcase build -u`.
Double-click the built .exe file. The process starts, but nothing appears on screen.
Kill the process using Task Manager, then examine the log file under `AppData/Local/Developer Name`. The exception trace is not there.
### Expected behavior
Exceptions thrown by `startup` should be shown in a dialog, and written to a log file.
### Environment
- Operating System: Windows 10 and 11
- Python version: 3.9
- Software versions:
- Briefcase: 0.3.23, and current main branch
- Toga: 0.5.1
### Additional context
Possibly related:
* https://github.com/beeware/toga/issues/2806
Contributor guide
Research direction
Reproduce the failure by making the app's startup entry point raise before the main window is shown, then run `briefcase build -u` and launch the Windows executable. Inspect the WinForms startup exception path and compare it with pre-startup and event-handler handling. Done means the exception appears in a dialog and is written to the log under `AppData/Local/Developer Name`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100