windows: Improve error message for credential write failures (#46221)

Xiaobo Liu created

Release Notes:

- Improved Display the actual Windows error message when writing
credentials to Credential Manager fails, instead of the generic "Failed
to write API key to keychain" message. This helps users diagnose issues
like permission problems.

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>

Change summary

crates/gpui/src/platform/windows/platform.rs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

Detailed changes

crates/gpui/src/platform/windows/platform.rs 🔗

@@ -635,7 +635,14 @@ impl Platform for WindowsPlatform {
                 UserName: PWSTR::from_raw(username.as_mut_ptr()),
                 ..CREDENTIALW::default()
             };
-            unsafe { CredWriteW(&credentials, 0) }?;
+            unsafe {
+                CredWriteW(&credentials, 0).map_err(|err| {
+                    anyhow!(
+                        "Failed to write credentials to Windows Credential Manager: {}",
+                        err,
+                    )
+                })?;
+            }
             Ok(())
         })
     }