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

Correct FormatException when parsing Invariant-locale numbers in user's locale #125

Merged
merged 3 commits into from Dec 20, 2023

Conversation

gbakeman
Copy link
Contributor

@gbakeman gbakeman commented Dec 12, 2023

Several people are reporting that WinNUT is crashing when it attempts to parse the ups.realpower.nominal variable that's returned from the server.

This PR refactors some code in the UPS_Device class related to variable retrieval and parsing. Special precaution is added around the power variable parsing and calculation, and correct variable types are now used throughout (Integer -> Double.) In addition, I now understand that the .Parse() method strictly adheres to the executing machine's locale and will throw the relevant exception should it encounter any number beyond the current locale, unless a locale is manually specified. I've updated how UPS_Device refers to the Invariant culture, which is now used throughout the class. This should completely resolve FormatExceptions revolving around power variable parsing.

However, this fix points to a greater need for parser and variable handling improvements. Specifically, UPS variables and requests should be represented by individual objects with appropriate metadata attached. This will allow for better state control and error handling by the client. Consider prioritizing migrating WinNUT to the NUTDotNet library.

Several people are reporting that WinNUT is crashing when it attempts to parse the `ups.realpower.nominal` variable that's returned from the server. Adding in some logging to troubleshoot that, as well as a few other log lines to better describe the startup procedure in log files.
@gbakeman gbakeman linked an issue Dec 12, 2023 that may be closed by this pull request
Applying several changes to the `UPS_Device` class:

- Made `Retrieve_UPS_Datas` private, and removed leftover commented code
- Merged `GetPowerUsage` function into main data retrieval loop since no other code referred to it.
- Wrapped power variable parsing into try block to log parsing errors. NUT and other exceptions will continue to be raised.
- Reorganized some comments around battery calculations.
@gbakeman gbakeman added bug Something isn't working enhancement New feature or request labels Dec 13, 2023
@gbakeman gbakeman self-assigned this Dec 13, 2023
@gbakeman gbakeman added this to the 2.3 Stable Release milestone Dec 13, 2023
- Create region for Static/ReadOnly variables for reference.
- Change how the invariant culture is provided to code in this class, and attempting to make it as static as possible.
- Applied invariant culture to load variable parsing code, hopefully fixing #125.
- Completely define timers and connect event handlers in initializing code.
@gbakeman gbakeman changed the title Troubleshoot nominalpower parse errors Correct FormatException when parsing Invariant-locale numbers in user's locale Dec 20, 2023
@gbakeman gbakeman merged commit e4f1298 into dev-2.3 Dec 20, 2023
1 check passed
@gbakeman gbakeman deleted the 123-formatexception-getpowerusage branch December 20, 2023 22:01
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.

FormatException in GetPowerUsage causes repeated disconnects
1 participant