tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
79.49k stars 2.36k forks source link

[feat] Catch tauri errors #10157

Open thewh1teagle opened 2 days ago

thewh1teagle commented 2 days ago

Describe the problem

Some users have an old version of webview2. if it's too old, the internal function create_webview will fail to run, tauri will log the error, but the app will still run in the background without show any error or crash the thread.

Describe the solution you'd like

Let me catch such errors. currently I don't get anything from it. I even have a panic hook, but it doesn't kick in since seems like the event loop just keep runing.

Alternatives considered

-

Additional context

https://github.com/thewh1teagle/vibe/issues/153#issuecomment-2198800744

Legend-Master commented 2 days ago

Seems like we use ICoreWebView2Environment10 which requires 101+ to support setting incognito mode, maybe we can skip that cast if we don't use incognito?

https://github.com/tauri-apps/wry/blob/f9e6bcc032369c6d5e7ce0284406953a16da3d82/src/webview2/mod.rs#L330-L331 https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environment10?view=webview2-1.0.2478.35 https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10121039

Seems like this is also when theme API gets added, probably could document when it's added and skip it instead of returning error for unsupported platforms

Let me catch such errors

I might be wrong but looks like you're using expect here?

https://github.com/thewh1teagle/vibe/blob/434e922ac386c3a45e989b094c8d25a85895eb5c/desktop/src-tauri/src/setup.rs#L73

thewh1teagle commented 1 day ago

I might be wrong but looks like you're using expect here?

Let me catch such errors. currently I don't get anything from it. I even have a panic hook, but it doesn't kick in since seems like the event loop just keep runing.

Legend-Master commented 1 day ago

I don't quite get it to be honest, expect will panic the thread on error, if you want to handle the error you can just use the returned Result from it or do you mean it's crashing at somewhere else?

thewh1teagle commented 1 day ago

I don't quite get it to be honest, expect will panic the thread on error, if you want to handle the error you can just use the returned Result from it or do you mean it's crashing at somewhere else?

Sorry, I should have explained it better. Even though I'm using expect, it never gets there. Like I said, if the webview fails to start (like with an old version), tauri logs the error, but expect isn't hit, and the event loop just keeps running. Hope that makes more sense!

Legend-Master commented 1 day ago

Ah, got it

C:\Users\1234>[2024-06-30T23:19:39Z DEBUG vibe_desktop] Vibe App Running
[2024-06-30T23:19:39Z ERROR tauri_runtime_wry] failed to create webview: WebView2 error: WindowsError(Error { code: HRESULT(0x80004002), message: "No such interface supported" })
[2024-06-30T23:19:39Z DEBUG vibe_desktop::setup] webview version: 100.0.1185.36
[2024-06-30T23:19:39Z DEBUG vibe_desktop::setup] CPU Features:
    AVX: true
    AVX2: true
    AVX512: true
    AVX512-VBMI: true
    AVX512-VNNI: true
    FMA: true
    F16C: true
[2024-06-30T23:19:39Z DEBUG vibe_desktop::setup] COMMIT_HASH: cc1bb4f721a794c58081b139e57808c6ec8e00a5

https://github.com/thewh1teagle/vibe/blob/434e922ac386c3a45e989b094c8d25a85895eb5c/desktop/src-tauri/src/setup.rs#L73

Looking at this, it seems like the failed to create webview error happened before WebviewWindowBuilder::build, presumably before the whole setup function, and that probably explained why the panic hook didn't work

It seems like it's creating windows before setup hook which should be from config files but I don't see any windows from your config files, pretty strange

thewh1teagle commented 1 day ago

and that probably explained why the panic hook didn't work

In addition the process kept running (the process was still listed in task manager)

bukowa commented 1 day ago

Is it possible to also detect an outdated webview version and ask the user to update?

Legend-Master commented 1 day ago

Yes, with webview_version