Skip to content

Fix crash when AT command responses have unexpected format in device info hook#73

Open
clndwhr wants to merge 1 commit intodr-dolomite:developmentfrom
clndwhr:bug/fix-about-page-parsing-when-data-isn't-parsable
Open

Fix crash when AT command responses have unexpected format in device info hook#73
clndwhr wants to merge 1 commit intodr-dolomite:developmentfrom
clndwhr:bug/fix-about-page-parsing-when-data-isn't-parsable

Conversation

@clndwhr
Copy link
Copy Markdown
Contributor

@clndwhr clndwhr commented Mar 12, 2026

🐛 Fix crash when AT command responses have unexpected format in device info hook

Problem

The useAboutData hook was vulnerable to runtime crashes when AT command responses didn't match the expected string format. Direct string splitting operations like .split("\n")[1] would throw errors if:

  • Response had fewer lines than expected
  • Missing colons or commas in structured data
  • Array indices were out of bounds
  • Response was empty or malformed

This caused the entire About page to crash when device responses were incomplete or in unexpected formats.

Solution

Implemented robust error handling with a safeParse helper function that:

Safe Parsing Logic

  • Graceful fallback: Returns "N/A" instead of crashing when parsing fails
  • Bounds checking: Validates array indices before accessing them
  • Try-catch protection: Wraps all parsing operations to prevent runtime errors
  • Null-safe operators: Handles missing rawData entries with ?. and ||

Parsing Operations Protected

  • Basic fields: manufacturer, model, firmwareVersion, imsi, imei
  • Complex nested parsing: phoneNum, currentDeviceIP, lanGateway
  • IPv4/IPv6 addresses: wwanIPv4, wwanIPv6
  • Network info: lteCategory, LTE3GppRel, NR3GppRel
  • ICCID: Smart colon-based parsing

Helper Function Features

safeParse(response, ["split|\n|1", "split|:|1", "split|,|3", "removeQuotes", "trim"])

Copilot AI review requested due to automatic review settings March 12, 2026 20:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors useAboutData’s device-response parsing to be more defensive against unexpected/malformed backend output, reducing the likelihood of runtime errors while populating the About/Device Info UI.

Changes:

  • Added a safeParse helper to centralize and harden string-parsing steps with a fallback value.
  • Updated processedData field extraction to use safeParse and optional chaining for safer access.
  • Made initial deviceUptime extraction more tolerant of missing uptime fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants