Feat handle open port error#22
Conversation
…te method descriptions comments
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive error handling for serial port operations in the littlebot_base driver. The changes introduce a new error type system with explicit error codes instead of boolean success/failure indicators, and adds an initialization method to handle port opening separately from object construction.
Changes:
- Introduces
SerialErrorenum to represent different serial port error conditions - Adds
init()method toILittlebotDriverinterface for explicit initialization after construction - Updates serial port methods (
open,close,read,write) to return error codes and be markednoexcept - Creates
mapSerialError()helper method to translate SerialError to DriverError - Adds new DriverError enum values for serial-specific errors
- Removes early serial port opening from factory, deferring to explicit init() call
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| littlebot_base/include/littlebot_base/i_serial_port.hpp | Adds SerialError enum, updates interface methods to return SerialError and be noexcept, fixes spelling errors in comments |
| littlebot_base/include/littlebot_base/serial_port.hpp | Updates method signatures to match new interface (SerialError return types, noexcept) |
| littlebot_base/include/littlebot_base/i_littlebot_driver.hpp | Adds init() pure virtual method, removes constructor from interface, adds protected default constructor |
| littlebot_base/include/littlebot_base/littlebot_driver.hpp | Adds init() method, port/baudrate parameters and member variables, updates documentation |
| littlebot_base/include/littlebot_base/types.hpp | Adds four new DriverError enum values for serial port errors with aligned comments |
| littlebot_base/src/serial_port.cpp | Implements error handling in open/close methods with try-catch blocks and SerialError returns |
| littlebot_base/src/littlebot_driver.cpp | Implements init() and mapSerialError() methods, removes base class constructor call |
| littlebot_base/src/littlebot_driver_factory.cpp | Removes serial port opening from factory, adds port/baudrate to constructor call |
| littlebot_base/test/mocks/mock_serial_port.hpp | Updates mock to match new interface signatures with SerialError and noexcept |
| littlebot_base/test/test_littlebot_driver.cpp | Adds default mock behavior for open() returning SerialError::None, updates constructor call with port/baudrate |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Set default behavior for open to return true | ||
| ON_CALL(*serial_, open(testing::_, testing::_)) | ||
| .WillByDefault(testing::Return(littlebot_base::SerialError::None)); | ||
|
|
||
| driver_ = std::make_unique<littlebot_base::LittlebotDriver>( | ||
| serial_, state_buffer_, command_buffer_, joint_names_); | ||
| serial_, state_buffer_, command_buffer_, joint_names_, "/dev/TEST_PORT", 115200); | ||
| } |
There was a problem hiding this comment.
The PR claims to have added tests to cover the changes (as stated in the checklist), but there are no tests for the new init() method. Tests should be added to verify that init() correctly handles various SerialError conditions (None, PortUnavailable, InsufficientPermissions, ConfigBaudrateFailed, AlreadyOpen) and properly maps them to the corresponding DriverError values.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Pull Request
Description
Iplement handle for open and close serial port erros. create new init and mapErros methods
Related Issue(s)
Checklist