Return error from NewGTU7 instead of panicking#20
Merged
Conversation
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update Gtu7 sensor and serial drivers implementation based on feedback
Return error from NewGTU7 instead of panicking
Jan 16, 2026
rustyeddy
approved these changes
Jan 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors the NewGTU7 constructor to follow Go error handling conventions by returning an error instead of panicking when serial initialization fails.
Changes:
- Modified
NewGTU7to return(*GTU7, error)instead of*GTU7 - Replaced panic on
OpenSerialfailure with proper error propagation - Updated test to handle the new error return value
- Cleaned up unused dependencies from go.mod and go.sum
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sensors/gtu7.go | Changed function signature to return error and replaced panic with error return |
| sensors/gtu7_test.go | Updated test to handle error return from NewGTU7 |
| go.mod | Removed unused dependencies and moved golang.org/x/sys to direct dependencies |
| go.sum | Removed checksums for unused dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
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.
The
NewGTU7constructor panics when serial initialization fails, violating Go error handling conventions and making the API unsafe.Changes
NewGTU7signature to return(*GTU7, error)OpenSerialfailure instead of panickingSerialFactoryExample
Testing
TestGTU7_PrefersRMCOverVTGvalidates success path with Reader injectionTestNewGTU7_OpenSerialErrorvalidates error propagation when OpenSerial failsAligns with error handling pattern used in other constructors like
NewADS1115.💡 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.