Skip to content

Commit

Permalink
fix: Provide helpful error message if this is not bound (#157)
Browse files Browse the repository at this point in the history
* fix: Provide helpful error message if `this` is not bound

* Update HybridFunction.hpp
  • Loading branch information
mrousavy authored Sep 25, 2024
1 parent 96d9c29 commit 377fbd8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/react-native-nitro-modules/cpp/core/HybridFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,14 @@ class HybridFunction final {
// 1. Convert jsi::Value to jsi::Object
#ifdef NITRO_DEBUG
if (!value.isObject()) [[unlikely]] {
throw jsi::JSError(runtime, "Cannot " + getHybridFuncDebugInfo<THybrid>(funcKind, funcName) + " - `this` is not bound!");
throw jsi::JSError(runtime, "Cannot " + getHybridFuncDebugInfo<THybrid>(funcKind, funcName) +
" - `this` is not bound! Suggestions:\n"
"- Did you accidentally destructure the `HybridObject`? (`const { " +
funcName +
" } = ...`)\n"
"- Did you call `dispose()` on the `HybridObject` before?"
"- Did you accidentally call `" +
funcName + "` on the prototype directly?");
}
#endif
jsi::Object object = value.getObject(runtime);
Expand All @@ -183,10 +190,12 @@ class HybridFunction final {
if (!object.hasNativeState(runtime)) [[unlikely]] {
throw jsi::JSError(runtime, "Cannot " + getHybridFuncDebugInfo<THybrid>(funcKind, funcName) +
" - `this` does not have a NativeState! Suggestions:\n"
"- Did you accidentally destructure the `HybridObject` and lose a reference to the original object?\n"
"- Did you accidentally destructure the `HybridObject`? (`const { " +
funcName +
" } = ...`)\n"
"- Did you call `dispose()` on the `HybridObject` before?"
"- Did you accidentally call `" +
funcName + "` on the prototype directly?\n");
funcName + "` on the prototype directly?");
}
#endif

Expand Down

0 comments on commit 377fbd8

Please sign in to comment.