Skip to content

Remove panic from GTU7 constructor and add documentation#26

Closed
Copilot wants to merge 4 commits intogtu7from
copilot/sub-pr-16-a17fd3af-97c0-48c3-a918-757904586fbf
Closed

Remove panic from GTU7 constructor and add documentation#26
Copilot wants to merge 4 commits intogtu7from
copilot/sub-pr-16-a17fd3af-97c0-48c3-a918-757904586fbf

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

The NewGTU7 constructor panicked on serial port errors and lacked documentation.

Changes:

  • Deferred serial port initialization to Run() – Constructor now cannot fail, matching patterns used by LED, BME280, and VH400 devices
  • Added godoc – Documents parameters, behavior, and test injection via cfg.Reader
  • Refactored struct – Stores GTU7Config directly instead of extracted fields

Before:

func NewGTU7(cfg GTU7Config) *GTU7 {
    port, err := cfg.Factory.OpenSerial(cfg.Serial)
    if err != nil {
        panic(err)  // Constructor can crash
    }
    return &GTU7{name: cfg.Name, r: port, ...}
}

After:

// NewGTU7 constructs a GTU7 GPS sensor with the given configuration.
//
// The GTU7 reads NMEA 0183 sentences (GPGGA, GPRMC, GPVTG) from a serial port
// and emits GPSFix updates. Serial port initialization is deferred to Run(),
// so this constructor cannot fail.
func NewGTU7(cfg GTU7Config) *GTU7 {
    return &GTU7{cfg: cfg, out: make(chan GPSFix, 4)}
}

func (g *GTU7) Run(ctx context.Context) error {
    port, err := g.cfg.Factory.OpenSerial(g.cfg.Serial)
    if err != nil {
        return err  // Proper error handling
    }
    defer func() { _ = port.Close() }()
    // ...
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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 fips140/mlkem (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-131449314c26 -j DROP Trust_ECC_Root-0-n1 /opt/hostedtoolc--format=format:%H %ct %D test ba47f30cb112e8e8git /tmp/go-build201config e3f28caf test -e ommScope_Public_Trust_RSA_Root-02.pem ache/go/1.24.11/x64/pkg/tool/linux_amd64/vet /usr/bin/test --noprofile ux_amd64/compile--wait it test (dns block)
  • gopkg.in
    • Triggering command: /update-job-proxy /update-job-proxy fips140/mlkem (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-131449314c26 -j DROP Trust_ECC_Root-0-n1 /opt/hostedtoolc--format=format:%H %ct %D test ba47f30cb112e8e8git /tmp/go-build201config e3f28caf test -e ommScope_Public_Trust_RSA_Root-02.pem ache/go/1.24.11/x64/pkg/tool/linux_amd64/vet /usr/bin/test --noprofile ux_amd64/compile--wait it test (dns block)
  • periph.io
    • Triggering command: /update-job-proxy /update-job-proxy fips140/mlkem (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-131449314c26 -j DROP Trust_ECC_Root-0-n1 /opt/hostedtoolc--format=format:%H %ct %D test ba47f30cb112e8e8git /tmp/go-build201config e3f28caf test -e ommScope_Public_Trust_RSA_Root-02.pem ache/go/1.24.11/x64/pkg/tool/linux_amd64/vet /usr/bin/test --noprofile ux_amd64/compile--wait it 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 Remove panic from GTU7 constructor and add documentation Jan 16, 2026
Copilot AI requested a review from rustyeddy January 16, 2026 17:49
@rustyeddy rustyeddy closed this Jan 17, 2026
@rustyeddy rustyeddy deleted the copilot/sub-pr-16-a17fd3af-97c0-48c3-a918-757904586fbf branch January 17, 2026 16:34
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