-
Notifications
You must be signed in to change notification settings - Fork 170
[onert] Add API function for retrieving last error message #16282
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
base: master
Are you sure you want to change the base?
Conversation
|
Small info how this change will be used. If approved, it will be possible to get proper error message string in the python binding as follows: --- a/runtime/onert/api/python/src/wrapper/nnfw_api_wrapper.cc
+++ b/runtime/onert/api/python/src/wrapper/nnfw_api_wrapper.cc
@@ -24,27 +24,26 @@ namespace onert::api::python
namespace py = pybind11;
-void ensure_status(NNFW_STATUS status)
+void NNFW_SESSION::ensure_status(NNFW_STATUS status)
{
switch (status)
{
case NNFW_STATUS::NNFW_STATUS_NO_ERROR:
return;
case NNFW_STATUS::NNFW_STATUS_ERROR:
- throw NnfwError("NNFW_STATUS_ERROR");
+ throw NnfwError(nnfw_get_last_error_message(session));
case NNFW_STATUS::NNFW_STATUS_UNEXPECTED_NULL:
- throw NnfwUnexpectedNullError("NNFW_STATUS_UNEXPECTED_NULL");
+ throw NnfwUnexpectedNullError(nnfw_get_last_error_message(session));
case NNFW_STATUS::NNFW_STATUS_INVALID_STATE:
- throw NnfwInvalidStateError("NNFW_STATUS_INVALID_STATE");
+ throw NnfwInvalidStateError(nnfw_get_last_error_message(session));
case NNFW_STATUS::NNFW_STATUS_OUT_OF_MEMORY:
- throw NnfwOutOfMemoryError("NNFW_STATUS_OUT_OF_MEMORY");
+ throw NnfwOutOfMemoryError(nnfw_get_last_error_message(session));
case NNFW_STATUS::NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE:
- throw NnfwInsufficientOutputError("NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE");
+ throw NnfwInsufficientOutputError(nnfw_get_last_error_message(session));
case NNFW_STATUS::NNFW_STATUS_DEPRECATED_API:
- throw NnfwDeprecatedApiError("NNFW_STATUS_DEPRECATED_API");
- default:
- throw NnfwError("NNFW_UNKNOWN_ERROR");
+ throw NnfwDeprecatedApiError(nnfw_get_last_error_message(session));
}
+ throw NnfwError(nnfw_get_last_error_message(session));
}
NNFW_LAYOUT getLayout(const char *layout) |
There was a problem hiding this 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 introduces a new API function nnfw_get_last_error_message() to retrieve error messages from failed API calls, replacing the previous approach of writing errors to std::cerr. The implementation includes comprehensive refactoring to set appropriate error messages in all API functions using a new _last_error_message member variable in the Session class.
- Adds
nnfw_get_last_error_message()API function for retrieving last error message - Refactors error handling throughout Session methods to use
setLastErrorMessage()instead ofstd::cerr - Converts deprecated API functions from static to instance methods to enable error message tracking
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| runtime/onert/api/nnfw/include/nnfw.h | Adds public API declaration for nnfw_get_last_error_message() |
| runtime/onert/api/nnfw/src/APIImpl.cc | Implements nnfw_get_last_error_message() and updates deprecated API wrappers to use instance methods |
| runtime/onert/api/nnfw/src/Session.h | Adds _last_error_message member, get_last_error_message(), setLastErrorMessage() methods, and moves getTensorIndexImpl() to private |
| runtime/onert/api/nnfw/src/Session.cc | Refactors all API methods to call setLastErrorMessage() for error conditions and removes std::cerr writes; refactors loadModel() helper to throw exceptions |
| runtime/tests/nnfw_api/src/NNPackageTests/SessionCreated.test.cc | Adds test for error message retrieval and moves deprecated API tests from SingleSession |
| runtime/tests/nnfw_api/src/NNPackageTests/SingleSession.test.cc | Removes deprecated API tests (moved to SessionCreated) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This commit adds dedicated API function nnfw_get_last_error_message() for retrieving last error message in case when other functions return status code other than NNFW_STATUS_NO_ERROR. ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <[email protected]>
5659a81 to
f63a698
Compare
|
@hseok-oh Could you please take a look as this and let me know what do you think? If you like such approach (new API for getting the last error message) I can split that PR into smaller PRs (if you prefer very narrow PRs in terms of scope of changes). Basically, I will submit every commit from this draft as a separate PR. There is one thing that you should look at, though. The signature of this new API is as follows: pros:
cons:
Other approach is to hold the error message in the static variable (preferably in the thread local variable) just like the |
This PR adds dedicated API function
nnfw_get_last_error_message()for retrieving last error message in case when other functions return status code other thanNNFW_STATUS_NO_ERROR.It also does small refactoring in order to properly set last error message in all API calls which includes:
loadModel()helper so it will not print tostd:cerrSession::deprecatedfunction to be non-static to allow setting last error message in itgetTensorIndexImpl()helper to be a private member of Session to allow setting last error message in itAlso this PR adds small check in the
ValidationTestSessionCreated.neg_load_session_2test case to verifynnfw_get_last_error_message()API correctness.This PR is fix for one of the issues diagnosed in #16102 (comment)
ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy [email protected]