Skip to content
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

Consistently assign defaults when prop parsing fails #36163

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions ReactCommon/react/debug/react_native_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
// test before moving on. When all issues have been found, maybe we can use
// `UNDEBUG` flag to disable NDEBUG in debug builds on Android.

// Asserting is appropriate for conditions that:
// 1. May or may not be recoverable, and
// 2. imply there is a bug in React Native when violated.
// For recoverable conditions that can be violated by user mistake (e.g. JS
// code passes an unexpected prop value), consider react_native_expect instead.

#include "flags.h"

#undef react_native_assert
Expand Down
41 changes: 41 additions & 0 deletions ReactCommon/react/debug/react_native_expect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// No header guards since it is legitimately possible to include this file more
// than once with and without REACT_NATIVE_DEBUG.

// react_native_expect is a non-fatal counterpart of react_native_assert.
// In debug builds, when an expectation fails, we log and move on.
// In release builds, react_native_expect is a noop.

// react_native_expect is appropriate for recoverable conditions that can be
// violated by user mistake (e.g. JS code passes an unexpected prop value).
// To enforce invariants that are internal to React Native, consider
// react_native_assert (or a stronger mechanism).
// Calling react_native_expect does NOT, by itself, guarantee that the user
// will see a helpful diagnostic (beyond a low level log). That concern is the
// caller's responsibility.

#include "flags.h"

#undef react_native_expect

#ifndef REACT_NATIVE_DEBUG

#define react_native_expect(e) ((void)0)

#else // REACT_NATIVE_DEBUG

#include <glog/logging.h>
#include <cassert>

#define react_native_expect(cond) \
if (!(cond)) { \
LOG(ERROR) << "react_native_expect failure: " << #cond; \
}

#endif // REACT_NATIVE_DEBUG
Loading