nutdotnet / WinNUT-Client

WinForms-based client for monitoring your Uninterruptible Power Supply (UPS) connected to a Network UPS Tools (NUT) server.
GNU General Public License v3.0
186 stars 18 forks source link

Standard Exception logging subroutine, variable error handling, misc. bugfixes #131

Closed gbakeman closed 4 months ago

gbakeman commented 5 months ago

Upgrade logging

There's some more room for improvement in how logs are created.

Miscellaneous bugfixes

System.OverflowException

User reports an OverflowException was occurring where the UPS_BattCh double variable is cast to an Integer. It's not used for anything, so I'm removing it in the hopes that this will solve the issue.

System.OverflowException: An arithmetic operation causes an overflow. In the WinNUT_Client.WinNUT.Event_UpdateBatteryState(String Reason) location WinNUT_V2\WinNUT-Client\WinNUT.vb: line number 533 At WinNUT_Client.WinNUT.UPSDisconnectedEvent() location WinNUT_V2\WinNUT-Client\WinNUT.vb: line number 359 at WinNUT_Client_Common.UPS_Device.DisconnectedEventHandler.Invoke() at WinNUT_Client_Common.UPS_Device.Disconnect(Boolean cancelReconnect, Boolean forceful) at location WinNUT_V2\WinNUT-Client_Common\UPS_Device.vb: Line number 185 at WinNUT_Client_Common.UPS_Device.Retrieve_UPS_Datas(Object sender, EventArgs e) location WinNUT_V2\WinNUT-ClientCommon\UPS Device.vb: Line number 366 at System.Windows.Forms.Timer.OnTick(EventArgs) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

https://github.com/nutdotnet/WinNUT-Client/pull/131/commits/43ac206f7e67224ec2c79f7e47c8f1b83c6e23e5

System.NullReferenceException

In addition, the user found another bug where the View and Delete log controls were enabled (logging option enabled) while the log file was not present. More protections have been added to prevent this problem.

System.NullReferenceException: The object reference is not set to an instance of the object. At WinNUT_Client_Common.Logger.get_LogFilePath() location D:aWinNUT-ClientWinNUT-ClientWinNUT_V2WinNUT-Client_CommonLogger.vb: line number 91 At WinNUT_Client.Pref_Gui.Btn_ViewLog_Click(Object sender, EventArgs e) position D:aWinNUT-ClientWinNUT-ClientWinNUT_V2WinNUT-ClientPref_Gui.vb: line number 341 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message&m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message&m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam,

https://github.com/nutdotnet/WinNUT-Client/pull/131/commits/da13d50a2cda2728e6a1e0cc008d4cba8697b6b0

System.OverflowException and default values

Similar to the first report, another OverflowException is reported having to do with processing of UPS variables. It seems like this user's NUT server is reporting mostly out-of-range values for its variables.

[6424, UPS_Device]: System.OverflowException thrown in mscorlib Message: TimeSpan overflows because it lasts too long. at System.TimeSpan.Interval(Double value, Int32 scale) at System.TimeSpan.FromSeconds(Double value) At WinNUT_Client.WinNUT.Update_UPS_Data() position D:aWinNUT-ClientWinNUT-ClientWinNUT_V2WinNUT-ClientWinNUT.vb: line number 734 At WinNUT_Client_Common.UPS_Device.Retrieve_UPS_Datas(Object sender, EventArgs e) location D:aWinNUT-ClientWinNUT-ClientWinNUT_V2WinNUT-Client_CommonUPS_Device.vb: line number 362