Skip to content

Commit d114d7d

Browse files
dannysufacebook-github-bot
authored andcommitted
Render Error objects in CDT (#1471) (#1471)
Summary: Original Author: [email protected] Original Git: 6b45693 Original Reviewed By: hoxyq Original Revision: D60598446 X-link: facebook/react-native#45990 Pull Request resolved: #1471 Changelog: [General][Added]: support for rendering Error objects in Chrome DevTools console As discussed in [Linkifying and symbolicating JavaScript Error stacks in Fusebox](https://docs.google.com/document/d/1JI_PPzxFRwRNii6pcx-4Cb7g8UTrqnZHCxaoynntIrM/edit) by hoxyq, Error objects in CDT currently displays a big blob of string. In this diff, we send the correct CDT params. Reviewed By: mattbfb Differential Revision: D61574237 fbshipit-source-id: 73829455a50eb2e98a717cf2506edec10c9d758c
1 parent a9dd976 commit d114d7d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

API/hermes/cdp/RemoteObjectConverters.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ namespace m = ::facebook::hermes::cdp::message;
1818

1919
constexpr size_t kMaxPreviewProperties = 10;
2020

21+
static bool isObjectInstanceOfError(
22+
const jsi::Object &obj,
23+
facebook::jsi::Runtime &runtime) {
24+
return obj.instanceOf(
25+
runtime, runtime.global().getPropertyAsFunction(runtime, "Error"));
26+
}
27+
2128
static m::runtime::PropertyPreview generatePropertyPreview(
2229
facebook::jsi::Runtime &runtime,
2330
const std::string &name,
@@ -309,6 +316,16 @@ m::runtime::RemoteObject m::runtime::makeRemoteObject(
309316
if (options.generatePreview) {
310317
result.preview = generateArrayPreview(runtime, array);
311318
}
319+
} else if (isObjectInstanceOfError(obj, runtime)) {
320+
result.type = "object";
321+
result.subtype = "error";
322+
// T198854404 we should report subclasses of Error here, e.g. TypeError
323+
result.className = "Error";
324+
result.description =
325+
obj.getProperty(runtime, "stack").toString(runtime).utf8(runtime);
326+
if (options.generatePreview) {
327+
result.preview = generateObjectPreview(runtime, obj);
328+
}
312329
} else {
313330
result.type = "object";
314331
result.description = result.className = "Object";

0 commit comments

Comments
 (0)