Skip to content

HyundaiEurope: fix app crash from force-unwrapping a non-numeric status field#39

Open
MrL0 wants to merge 1 commit into
schmidtwmark:mainfrom
MrL0:fix/hyundai-eu-parser-force-unwrap
Open

HyundaiEurope: fix app crash from force-unwrapping a non-numeric status field#39
MrL0 wants to merge 1 commit into
schmidtwmark:mainfrom
MrL0:fix/hyundai-eu-parser-force-unwrap

Conversation

@MrL0

@MrL0 MrL0 commented Jun 28, 2026

Copy link
Copy Markdown

What this does

HyundaiEuropeAPIClient.getDoubleFromJson force-unwraps the optional Double(String):

case let value as String: return Double(value)!

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) is nil and 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):

case let value as String: return Double(value) ?? 0

0 is also this function's existing default: fallback, so the behavior is consistent — a non-numeric value now reads as 0 instead of crashing.

Testing

swift test290 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant