From e0573a140040133eda362371e0b668886aaef5d4 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 9 Feb 2024 20:07:48 -0600 Subject: [PATCH] io error --- crates/libs/core/src/error.rs | 9 +++++++++ crates/libs/core/src/imp/com_bindings.rs | 1 + crates/tests/error/tests/std.rs | 5 +++++ crates/tools/core/com_bindings.txt | 1 + 4 files changed, 16 insertions(+) diff --git a/crates/libs/core/src/error.rs b/crates/libs/core/src/error.rs index ef798193ff..7e618d106c 100644 --- a/crates/libs/core/src/error.rs +++ b/crates/libs/core/src/error.rs @@ -104,6 +104,15 @@ impl From for std::io::Error { } } +impl From for Error { + fn from(from: std::io::Error) -> Self { + match from.raw_os_error() { + Some(status) => HRESULT::from_win32(status as u32).into(), + None => crate::imp::E_UNEXPECTED.into(), + } + } +} + impl From for Error { fn from(_: std::string::FromUtf16Error) -> Self { Self { code: HRESULT::from_win32(crate::imp::ERROR_NO_UNICODE_TRANSLATION), info: None } diff --git a/crates/libs/core/src/imp/com_bindings.rs b/crates/libs/core/src/imp/com_bindings.rs index 1c92f715fd..d5945f7945 100644 --- a/crates/libs/core/src/imp/com_bindings.rs +++ b/crates/libs/core/src/imp/com_bindings.rs @@ -66,6 +66,7 @@ pub const E_BOUNDS: ::windows_core::HRESULT = ::windows_core::HRESULT(-214748363 pub const E_INVALIDARG: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147024809i32); pub const E_NOINTERFACE: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147467262i32); pub const E_OUTOFMEMORY: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147024882i32); +pub const E_UNEXPECTED: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147418113i32); ::windows_core::imp::com_interface!(IAgileObject, IAgileObject_Vtbl, 0x94ea2b94_e9cc_49e0_c0ff_ee64ca8f5b90); ::windows_core::imp::interface_hierarchy!(IAgileObject, ::windows_core::IUnknown); impl IAgileObject {} diff --git a/crates/tests/error/tests/std.rs b/crates/tests/error/tests/std.rs index 891c8782f8..b2d28f9f20 100644 --- a/crates/tests/error/tests/std.rs +++ b/crates/tests/error/tests/std.rs @@ -51,4 +51,9 @@ fn conversions() { format!("{std_error}"), "The parameter is incorrect. (os error -2147024809)" ); + + // Starting with std::io::Error... + let std_error = std::io::Error::from_raw_os_error(ERROR_INVALID_DATA.0 as i32); + let error: windows::core::Error = std_error.into(); + assert_eq!(error.code(), ERROR_INVALID_DATA.to_hresult()); } diff --git a/crates/tools/core/com_bindings.txt b/crates/tools/core/com_bindings.txt index ad68b374bb..50b43c1e5f 100644 --- a/crates/tools/core/com_bindings.txt +++ b/crates/tools/core/com_bindings.txt @@ -13,6 +13,7 @@ Windows.Win32.Foundation.E_INVALIDARG Windows.Win32.Foundation.E_NOINTERFACE Windows.Win32.Foundation.E_OUTOFMEMORY + Windows.Win32.Foundation.E_UNEXPECTED Windows.Win32.Foundation.JSCRIPT_E_CANTEXECUTE Windows.Win32.Foundation.RPC_E_DISCONNECTED Windows.Win32.Foundation.TYPE_E_TYPEMISMATCH