Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions runtime/core/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ class Result final {
* a non-Ok value.
*/
/* implicit */ Result(Error error)
: error_(error == Error::Ok ? Error::Internal : error),
hasValue_(false) {}
: error_(error == Error::Ok ? Error::Internal : error), hasValue_(false) {
if ET_UNLIKELY (error == Error::Ok) {
ET_LOG(
Debug,
"Attempted to create Result from Error::Ok, this has been converted to Error::Internal.");
}
}

/// Value copy constructor.
/* implicit */ Result(const T& val) : value_(val), hasValue_(true) {}
Expand Down
1 change: 1 addition & 0 deletions runtime/core/test/error_handling_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ TEST(ErrorHandlingTest, ResultBasic) {
}

TEST(ErrorHandlingTest, OkErrorNotPossible) {
executorch::runtime::runtime_init();
Result<uint32_t> r(Error::Ok);
ASSERT_FALSE(r.ok());
ASSERT_NE(r.error(), Error::Ok);
Expand Down
Loading