Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Feb 28, 2024

Conversation

gbakeman
Copy link
Contributor

@gbakeman gbakeman commented Feb 7, 2024

Upgrade logging

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

  • Created LogException subroutine - standard method for logging Exceptions.
  • Modified UPS_Device.Retrieve_UPS_Datas to use this subroutine for general exceptions.
  • Better handling of missing log file - disable controls in Prefs GUI when true
  • See also: Enhance Logging #93

Miscellaneous bugfixes

  • Corrected update interval setting and Prefs tooltip to accurately reflect that it's given in milliseconds. Fixes validation error in the Prefs GUI with default value.
  • Fixed main WinNUT titlebar being blank.
  • Made old preferences upgrade menu item enable and disable correctly.
  • Battery and voltage variables are each set to a more obvious error value (-1) when an error occurs while querying their values, rather than a more real-looking fallback value. See also: Stop substituting default/fallback values for UPS variables #116
  • Attempts to calculate battery charge and runtime values fail if important variables for each calculation are also missing. As a result, an error message is logged and the out of range values are left alone.

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-Client_Common\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)

43ac206

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,

da13d50

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

User reports that an OverflowException was occurring at line 587, where the `UPS_BattCh` double variable is cast to an Integer. It's not used for anything, so perhaps removing it will solve the issue.
@gbakeman gbakeman added the bug Something isn't working label Feb 7, 2024
@gbakeman gbakeman added this to the 2.3 Stable Release milestone Feb 7, 2024
@gbakeman gbakeman self-assigned this Feb 7, 2024
@gbakeman gbakeman linked an issue Feb 7, 2024 that may be closed by this pull request
- Don't attempt to open the log file if the object does not exist (shouldn't be able to reach this point anyways)
- Only enable view and delete controls if log file is present.
@gbakeman gbakeman changed the title Fix OverflowException in WinNUT.vb Addressing issues in #129 Feb 9, 2024
@gbakeman gbakeman changed the title Addressing issues in #129 Addressing issues in #129 - Enhance logging, misc. exceptions Feb 9, 2024
- Adding new `LogException` subroutine to Logger class; designed to ensure that exception data is thoroughly logged in the invariant culture language.
- Corrected update interval setting and Prefs tooltip to accurately reflect that it's given in milliseconds. Fixes validation error in the Prefs GUI with default value.
- Began adding code in WinNUT.vb to allow for testing system stop routines while debugging.
- Removed `LongProgramName` global variable; replaced throughout code with `ProgramName`. Fixes main WinNUT titlebar being blank.
- Battery and voltage properties are now set to an invalid value (-1) when they are unavailable, rather than the previous method of setting them to a "fallback" value. Partially addresses #116
- Attempt to calculate battery charge fails and leaves a log message if the battery voltage is unavailable.
- Attempt to calculate battery runtime fails if other consequential values are unavailable. This may be problematic for calculations that rely on a "good enough" default value. However, I currently don't see any scenario where that would be acceptable to someone relying on an accurate calculation.
- When UPS status is on battery, log an error if battery variables are unavailable when trying to determine if a stop action is needed. Will need to follow this up and warn the user that stop actions are unavailable if battery info isn't present.
- When battery runtime is unavailable to WinNUT, display localized message instead.
- Fixed some inverted logic for battery charge calculations
- Restructured how old pref checking is handled in WinNUT.vb. Menu item now disables correctly once the prefs have been removed.
@gbakeman gbakeman added the enhancement New feature or request label Feb 28, 2024
@gbakeman gbakeman changed the title Addressing issues in #129 - Enhance logging, misc. exceptions Standard Exception logging subroutine, variable error handling, misc. bugfixes Feb 28, 2024
@gbakeman gbakeman merged commit d68496a into dev-2.3 Feb 28, 2024
1 check passed
@gbakeman gbakeman deleted the 129-overflowexception-updatebatterystate branch February 28, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes relating to bad/out-of-range values reported by NUT server
1 participant