From 8cc45ed6b434fbd4369eac30f554c9889b5f2c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Sun, 18 Dec 2022 09:29:25 +0100 Subject: [PATCH] Handle legitimate exception for "expected" failures --- CommonHelpers/Log.cs | 8 ++++++++ SteamController/Devices/SteamController.cs | 6 +++++- SteamController/Devices/Xbox360Controller.cs | 6 +++++- SteamController/Helpers/SteamConfiguration.cs | 6 ++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CommonHelpers/Log.cs b/CommonHelpers/Log.cs index 5207b7e..66d6c72 100644 --- a/CommonHelpers/Log.cs +++ b/CommonHelpers/Log.cs @@ -105,5 +105,13 @@ namespace CommonHelpers scope.SetTag("type", type); }); } + + public static void DebugException(String type, Exception e) + { + } + + public static void DebugException(String type, Object? name, Exception e) + { + } } } diff --git a/SteamController/Devices/SteamController.cs b/SteamController/Devices/SteamController.cs index 89e82ef..2ae2656 100644 --- a/SteamController/Devices/SteamController.cs +++ b/SteamController/Devices/SteamController.cs @@ -120,7 +120,11 @@ namespace SteamController.Devices } catch (Exception e) { - TraceException("STEAM", "Update", e); + // Steam have disconnected device, which triggered exception + if (e.Message == "Could not send report to hid device. Error: -1") + DebugException("STEAM", "Update", e); + else + TraceException("STEAM", "Update", e); Fail(); } } diff --git a/SteamController/Devices/Xbox360Controller.cs b/SteamController/Devices/Xbox360Controller.cs index 1134ff7..257ec1d 100644 --- a/SteamController/Devices/Xbox360Controller.cs +++ b/SteamController/Devices/Xbox360Controller.cs @@ -96,7 +96,11 @@ namespace SteamController.Devices catch (System.ComponentModel.Win32Exception e) { // This is expected exception (as sometimes device will fail to connect) - TraceException("X360", "ConnectExpected", e); + // ERROR_SUCCESS, which likely means COM did not succeed + if (e.NativeErrorCode == 0) + DebugException("X360", "ConnectExpected", e); + else + TraceException("X360", "ConnectExpected", e); Fail(); return; } diff --git a/SteamController/Helpers/SteamConfiguration.cs b/SteamController/Helpers/SteamConfiguration.cs index a4f3911..98df7c0 100644 --- a/SteamController/Helpers/SteamConfiguration.cs +++ b/SteamController/Helpers/SteamConfiguration.cs @@ -340,6 +340,12 @@ namespace SteamController.Helpers File.Copy(configPath + ".orig", configPath, true); return true; } + catch (FileNotFoundException e) + { + // File was not found (which is valid as it might be before first start of the application) + Log.DebugException("STEAM", e); + return false; + } catch (DirectoryNotFoundException) { // Steam was installed, but got removed