From edbdc7b97c2be3170c9062b5165e5493eee60a96 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 28 Jan 2025 10:18:54 +0100 Subject: [PATCH] fix: #2957 replaces throwing exception with returning default values --- .../lib/src/device_info_plus_windows.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart index cb966bdb49..213a0b8fa6 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart @@ -3,6 +3,7 @@ library device_info_plus_windows; import 'dart:ffi'; import 'dart:typed_data'; +import 'dart:developer' as developer; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; import 'package:ffi/ffi.dart'; @@ -124,8 +125,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform { if (result != 0) { return memoryInKilobytes.value ~/ 1024; } else { - final error = GetLastError(); - throw WindowsException(HRESULT_FROM_WIN32(error)); + developer.log('Failed to get system memory', error: GetLastError()); + return 0; } } finally { free(memoryInKilobytes); @@ -149,7 +150,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform { if (result != 0) { return lpBuffer.toDartString(); } else { - throw WindowsException(HRESULT_FROM_WIN32(GetLastError())); + developer.log('Failed to get computer name', error: GetLastError()); + return ""; } } finally { free(lpBuffer); @@ -167,7 +169,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform { if (result != 0) { return lpBuffer.toDartString(); } else { - throw WindowsException(HRESULT_FROM_WIN32(GetLastError())); + developer.log('Failed to get user name', error: GetLastError()); + return ""; } } finally { free(pcbBuffer);