-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Pull Request resolved: #43911 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: tdn120 Differential Revision: D55797031 fbshipit-source-id: eb53ae671b0a7b5d277b931a11eb0fcd84c51a19
- Loading branch information
1 parent
8b8b85b
commit 51552e6
Showing
3 changed files
with
58 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
...ges/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.react.bridge | ||
|
||
/** | ||
* Utility class to make assertions that should not hard-crash the app but instead be handled by the | ||
* Catalyst app [JSExceptionHandler]. See the javadoc on that class for more information about our | ||
* opinion on when these assertions should be used as opposed to assertions that might throw | ||
* AssertionError Throwables that will cause the app to hard crash. | ||
*/ | ||
public object SoftAssertions { | ||
|
||
/** | ||
* Throw [AssertionException] with a given message. Use this method surrounded with `if` block | ||
* with assert condition in case you plan to do string concatenation to produce the message. This | ||
* logs an assertion with ReactSoftExceptionLogger, which decides whether or not to actually | ||
* throw. | ||
*/ | ||
@JvmStatic | ||
public fun assertUnreachable(message: String): Unit { | ||
ReactSoftExceptionLogger.logSoftException("SoftAssertions", AssertionException(message)) | ||
} | ||
|
||
/** | ||
* Asserts the given condition, throwing an [AssertionException] if the condition doesn't hold. | ||
* This logs an assertion with ReactSoftExceptionLogger, which decides whether or not to actually | ||
* throw. | ||
*/ | ||
@JvmStatic | ||
public fun assertCondition(condition: Boolean, message: String): Unit { | ||
if (!condition) { | ||
ReactSoftExceptionLogger.logSoftException("SoftAssertions", AssertionException(message)) | ||
} | ||
} | ||
|
||
/** | ||
* Asserts that the given object isn't null, throwing an [AssertionException] if it was. This logs | ||
* an assertion with ReactSoftExceptionLogger, which decides whether or not to actually throw. | ||
*/ | ||
@JvmStatic | ||
public fun <T> assertNotNull(instance: T?): T? { | ||
if (instance == null) { | ||
ReactSoftExceptionLogger.logSoftException( | ||
"SoftAssertions", AssertionException("Expected object to not be null!")) | ||
} | ||
return instance | ||
} | ||
} |