Skip to content

Fix parseLatLon to detect and return strconv.ParseFloat errors#23

Merged
rustyeddy merged 6 commits intogtu7from
copilot/sub-pr-16-de1d3de7-a1b2-4f50-a092-1e34cd01a9ce
Jan 17, 2026
Merged

Fix parseLatLon to detect and return strconv.ParseFloat errors#23
rustyeddy merged 6 commits intogtu7from
copilot/sub-pr-16-de1d3de7-a1b2-4f50-a092-1e34cd01a9ce

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

The parseLatLon function silently ignored strconv.ParseFloat errors, causing invalid coordinate strings to return (0, 0) — valid coordinates in the Gulf of Guinea — masking parse failures.

Changes:

  • Check and return errors from both latitude and longitude parsing with wrapped error messages
  • Add fmt import for error formatting
  • Add 7 test cases covering empty strings, invalid inputs, and hemisphere variations

Before:

la, _ := strconv.ParseFloat(lat, 64)
lo, _ := strconv.ParseFloat(lon, 64)

After:

la, err := strconv.ParseFloat(lat, 64)
if err != nil {
    return 0, 0, fmt.Errorf("parse latitude: %w", err)
}
lo, err := strconv.ParseFloat(lon, 64)
if err != nil {
    return 0, 0, fmt.Errorf("parse longitude: %w", err)
}

Callers in parseGPGGA and parseGPRMC already handle the error return appropriately.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 16, 2026 17:45
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 16, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-512b45f37a05 -j DOCKER-ISOLATION-STAGE-2 CA.pem /opt/hostedtoolc-e /home/dependabot/bin/test /tmp/go-build277git -trimpath e3f28caf test -e .pem ache/go/1.24.11/x64/pkg/tool/linux_amd64/vet /bin/test se 0974618/b212/vet--wait rgo/bin/git test (dns block)
  • gopkg.in
    • Triggering command: /update-job-proxy /update-job-proxy (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-512b45f37a05 -j DOCKER-ISOLATION-STAGE-2 CA.pem /opt/hostedtoolc-e /home/dependabot/bin/test /tmp/go-build277git -trimpath e3f28caf test -e .pem ache/go/1.24.11/x64/pkg/tool/linux_amd64/vet /bin/test se 0974618/b212/vet--wait rgo/bin/git test (dns block)
  • periph.io
    • Triggering command: /update-job-proxy /update-job-proxy (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-512b45f37a05 -j DOCKER-ISOLATION-STAGE-2 CA.pem /opt/hostedtoolc-e /home/dependabot/bin/test /tmp/go-build277git -trimpath e3f28caf test -e .pem ache/go/1.24.11/x64/pkg/tool/linux_amd64/vet /bin/test se 0974618/b212/vet--wait rgo/bin/git test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] WIP Address feedback on Gtu7 sensor and serial drivers implementation Fix parseLatLon to detect and return strconv.ParseFloat errors Jan 16, 2026
Copilot AI requested a review from rustyeddy January 16, 2026 17:48
@rustyeddy rustyeddy marked this pull request as ready for review January 17, 2026 16:10
Copilot AI review requested due to automatic review settings January 17, 2026 16:10
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

This PR fixes a bug in the parseLatLon function where strconv.ParseFloat errors were silently ignored, causing invalid coordinate strings to return (0, 0) instead of propagating the error. This masked parse failures since (0, 0) represents valid coordinates in the Gulf of Guinea.

Changes:

  • Added proper error handling for latitude and longitude parsing with descriptive wrapped error messages
  • Improved the empty string error message for clarity
  • Added the fmt import for error formatting
  • Added a new TestParseLatLon test function with 7 test cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
sensors/gtu7.go Fixed error handling in parseLatLon to check and return strconv.ParseFloat errors with wrapped messages; improved empty string error message
sensors/gtu7_test.go Added TestParseLatLon test function with test cases for valid coordinates, empty strings, and invalid inputs (incomplete implementation)

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

Comment thread sensors/gtu7_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rustyeddy rustyeddy merged commit ca03af4 into gtu7 Jan 17, 2026
@rustyeddy rustyeddy deleted the copilot/sub-pr-16-de1d3de7-a1b2-4f50-a092-1e34cd01a9ce branch January 17, 2026 16:15
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.

3 participants