-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XLink crashes app if any exceptions occur in XLink cpp files #59
Comments
This will likely best be addressed (for now) by doing function wide try/catch, until either the lib is C++ified or if more fine grained handling is added (though I assume most cases will be general issues, as libusb ret value handling is already fine grained) |
Got it. I will look into this late this week or next. I intend to mark functions I hesitate in using the function-level |
This is straightforward though needs supporting code. In XLink today, I saw how I need to handle libusb while managing exceptions. For example...
The exception handling has to be in Tracing all the code to find where to insert try/catch/freeResources is time consuming and error-prone.
|
At diablodale@2cfde5b is a wrapper class TODO
Factory approach (implemented in above commit)
Constructor approach (alternative)
|
diablodale@461e30a adds the Constructor-approach. However, I also updated the Factory-approach to be non-throwing. The Caller does not need try/catch and can always test the result with Any feedback on which approach is preferred? |
added PR to fix this issue. I need a few questions answered in the PR to move further. :-) |
I've pushed the last commit to draft PR above. It includes markdown and mermaid documentation for usage and object model for the libusb wrapper. Its really quite simple. 🔢 This wrapper replaces much of the old Xlink C-style code for its usb transport and fixes this issue. Moving forward, this issue's fixes and more will usually be in my fork at https://github.com/diablodale/XLink/ |
Xlink can easily crash due to the newer C++ code within it yet having no exception handling.
For example, the file
usb_host.cpp
has a lot of C++ code in it and most of it can throw exceptions. However, there is no exception handling in functions, e.g.getUSBDevices()
, to prevent their doomed cascade upward into standard-C code...which causes an app crash/segfault. 💥Since exceptions can be throw by trivial uses like
std::string(...)
orcontainer::at()
, I recommend that the top-level functions in all cpp files be markednoexcept
. Then add try/catch to all needed places to catch any exceptions and return relevant error codes instead. All modern editors like vscode and analyzers provide clear feedback of functions marked noexcept yet calling things which can throw.Setup
Repro
usb_host.cpp
and insert as the first line of the functiongetUSBDevices()
the following:throw std::runtime_error("crash me");
tests/color_camera_node_test
Result
App immediately crashes.
Expected
App somehow gracefully fails, in this case it should report it could find no usb devices.
The text was updated successfully, but these errors were encountered: