[onert] Add API function for retrieving last error message#16282
[onert] Add API function for retrieving last error message#16282hseok-oh merged 4 commits intoSamsung:masterfrom
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.
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.
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 |
|
@glistening could you please look at this draft and checks whether the direction of these changes is right? If so I will split that draft into separate PR (one commit per PR) to simplify the review of particular changes (there are some prerequisites/cleanups required before the core change can be merged). |
|
@arkq I am okay for this change. Also, it looks okay not to split this PR. Just swith to "Ready for review" to get other's opinion. cc @Samsung/one_onert |
|
I prefer to use parameter instead of pointer return to return message string: |
f63a698 to
fe6b56c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fe6b56c to
9fabc7b
Compare
| { | ||
| return NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE; | ||
| } | ||
| strcpy(buffer, _last_error_message.c_str()); |
There was a problem hiding this comment.
Please use strlcpy(buffer, _last_error_message.c_str(), length) instead of strcpy
There was a problem hiding this comment.
The strlcpy is a BSD extension and I can not see any prior usage of strlcpy in this repository. Using strlcpy will require linking with libbsd. Should I add libbsd as a dependency to this project?
There was a problem hiding this comment.
Hmm. Then please use strncpy such as copilot suggested. Runtime does not allow to use strcpy. (SVACE will complain this function)
There was a problem hiding this comment.
OK, replaced with strncpy to hopefully satisfy SVACE.
9fabc7b to
5df1e83
Compare
Upps... sorry... I've messed the last rebase :/ I'm using Ubuntu 25.10, so without that change I'm not able to test anything... |
ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
5df1e83 to
756de40
Compare
ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
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 <a.bokowy@samsung.com>
756de40 to
47ed86b
Compare
@hseok-oh Should I create a separate PR for that? Because it seems that the |
|
|
||
| if (!null_terminating(tensorname, MAX_TENSOR_NAME_LENGTH)) | ||
| { | ||
| setLastErrorMessage("Error during Session::getTensorIndexImpl : tensorname is too long"); |
There was a problem hiding this comment.
You fixed the wrong error message. 👍
glistening
left a comment
There was a problem hiding this comment.
LGTM for last error message. Moving unrelated changes to separate PR seems done.
|
@arkq IMO, the group name for deprecated function is invalid: |
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 a.bokowy@samsung.com