Skip to content

fix(v3/windows): systray panic#5703

Open
wayneforrest wants to merge 4 commits into
wailsapp:masterfrom
wayneforrest:fix/sytemtray-panic
Open

fix(v3/windows): systray panic#5703
wayneforrest wants to merge 4 commits into
wailsapp:masterfrom
wayneforrest:fix/sytemtray-panic

Conversation

@wayneforrest

@wayneforrest wayneforrest commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

When Explorer / the taskbar restarts, the tray icon is de-registered until the TaskbarCreated handler (reshowSystrays) re-adds it (~1s debounce). A SetIcon in that window reaches updateIcon

Shell_NotifyIcon(NIM_MODIFY) fails -> panic(syscall.GetLastError()).

When the thread's last-error is 0, GetLastError() is nil, in Go this is panic(nil) -> "panic called with nil argument", crashing the host app.

Apps that update the tray on a timer hit this; others rarely do.

Fixes # (issue)

1: Fix don not panic(nil) in systray updateIcon when NIM_MODIFY fails
2: Fix nil-deref in destroy()

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Stack trace from user:

os=windows
error: panic called with nil argument
stack:
github.com/wailsapp/wails/v3/pkg/application.(*windowsSystemTray).updateIcon
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/systemtray_windows.go:346
github.com/wailsapp/wails/v3/pkg/application.(*windowsSystemTray).setIcon
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/systemtray_windows.go:400
github.com/wailsapp/wails/v3/pkg/application.(*SystemTray).SetIcon.func1
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/systemtray.go:236
github.com/wailsapp/wails/v3/pkg/application.InvokeSync.func1
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/mainthread.go:28
github.com/wailsapp/wails/v3/pkg/application.(*windowsApp).invokeCallback
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/mainthread_windows.go:125
github.com/wailsapp/wails/v3/pkg/application.(*windowsApp).wndProc
at 
  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows system tray reliability when updating the tray icon. If an update fails, the app now logs a warning and safely retries later instead of crashing.
    • Made tray icon removal logging more robust, avoiding a potential issue when reporting errors during shutdown.
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Two error-handling fixes in windowsSystemTray on Windows: updateIcon replaces a panic on ShellNotifyIcon(NIM_MODIFY) failure with a warning log plus rollback of s.currentIcon; destroy fixes a potential nil-dereference by passing syscall.GetLastError() directly to the debug logger instead of calling .Error() on it.

Windows System Tray Error Handling

Layer / File(s) Summary
updateIcon rollback & destroy safe logging
v3/pkg/application/systemtray_windows.go
updateIcon now warns and restores the previous icon handle on NIM_MODIFY failure instead of panicking. destroy passes syscall.GetLastError() as a value to debug instead of calling .Error() on a potentially nil error.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

  • wailsapp/wails#4653: Broader system tray refactor in systemtray_windows.go touching ShellNotifyIcon handling and destroy-path cleanup.

Suggested labels

Bug, Windows, go, v3-alpha, size:M

Suggested reviewers

  • leaanthony

Poem

🐇 No more panic in the tray,
The icon rolls back, come what may.
A warning logged, a nil unwrapped right,
The system tray hops through the night.
Steady paws keep bugs at bay! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the Windows systray panic fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description covers the fix, motivation, change type, and Windows testing, with only the issue reference and doctor output left incomplete.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

2 participants