Skip to content

Commit cc64fa1

Browse files
Log when a Result is created from Error::ok
Differential Revision: D69870978 Pull Request resolved: #8577
1 parent fd318cc commit cc64fa1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

runtime/core/result.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ class Result final {
5959
* a non-Ok value.
6060
*/
6161
/* implicit */ Result(Error error)
62-
: error_(error == Error::Ok ? Error::Internal : error),
63-
hasValue_(false) {}
62+
: error_(error == Error::Ok ? Error::Internal : error), hasValue_(false) {
63+
if ET_UNLIKELY (error == Error::Ok) {
64+
ET_LOG(
65+
Debug,
66+
"Attempted to create Result from Error::Ok, this has been converted to Error::Internal.");
67+
}
68+
}
6469

6570
/// Value copy constructor.
6671
/* implicit */ Result(const T& val) : value_(val), hasValue_(true) {}

runtime/core/test/error_handling_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ TEST(ErrorHandlingTest, ResultBasic) {
110110
}
111111

112112
TEST(ErrorHandlingTest, OkErrorNotPossible) {
113+
executorch::runtime::runtime_init();
113114
Result<uint32_t> r(Error::Ok);
114115
ASSERT_FALSE(r.ok());
115116
ASSERT_NE(r.error(), Error::Ok);

0 commit comments

Comments
 (0)