HyundaiEurope: fix app crash from force-unwrapping a non-numeric status field#39
Open
MrL0 wants to merge 1 commit into
Open
HyundaiEurope: fix app crash from force-unwrapping a non-numeric status field#39MrL0 wants to merge 1 commit into
MrL0 wants to merge 1 commit into
Conversation
A non-numeric status field (empty, 'null', '--', unit-suffixed, or comma-decimal) makes Double(String) nil, so the ! traps and crashes the app while parsing a vehicle status (this helper feeds odometer, SOC, range, GPS). Match the Kia EU sibling (KiaEuropeAPIClient+Parsing.swift), which already uses Double(value) ?? 0; 0 is also this function's existing default fallback, so behavior stays consistent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
HyundaiEuropeAPIClient.getDoubleFromJsonforce-unwraps the optionalDouble(String):If the API returns a numeric status field as a non-numeric string — empty,
"null","--", a unit-suffixed value, or a comma-decimal —Double(value)isniland the!traps, crashing the app while parsing a vehicle status. This helper feeds odometer, SOC, range, GPS and similar fields, so one malformed value takes the app down. Hyundai EU is already one of the rougher regions (EU login/command reports in the tracker), which makes a hard crash here especially worth removing.The fix matches the Kia EU sibling, which already does the safe thing (
KiaEuropeAPIClient+Parsing.swift):0is also this function's existingdefault:fallback, so the behavior is consistent — a non-numeric value now reads as0instead of crashing.Testing
swift test— 290 tests pass. The existing Hyundai EU parsing tests cover the happy path, which is unchanged; this only affects the previously-crashing non-numeric case. Pure one-line safety change with no behavior change for valid payloads.Drafted with AI assistance; verified locally with
swift test.