Skip to content

Commit

Permalink
Render Error objects in CDT (#1471) (#1471)
Browse files Browse the repository at this point in the history
Summary:
Original Author: edmondc@meta.com
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
  • Loading branch information
dannysu authored and facebook-github-bot committed Aug 27, 2024
1 parent a9dd976 commit d114d7d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions API/hermes/cdp/RemoteObjectConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ namespace m = ::facebook::hermes::cdp::message;

constexpr size_t kMaxPreviewProperties = 10;

static bool isObjectInstanceOfError(
const jsi::Object &obj,
facebook::jsi::Runtime &runtime) {
return obj.instanceOf(
runtime, runtime.global().getPropertyAsFunction(runtime, "Error"));
}

static m::runtime::PropertyPreview generatePropertyPreview(
facebook::jsi::Runtime &runtime,
const std::string &name,
Expand Down Expand Up @@ -309,6 +316,16 @@ m::runtime::RemoteObject m::runtime::makeRemoteObject(
if (options.generatePreview) {
result.preview = generateArrayPreview(runtime, array);
}
} else if (isObjectInstanceOfError(obj, runtime)) {
result.type = "object";
result.subtype = "error";
// T198854404 we should report subclasses of Error here, e.g. TypeError
result.className = "Error";
result.description =
obj.getProperty(runtime, "stack").toString(runtime).utf8(runtime);
if (options.generatePreview) {
result.preview = generateObjectPreview(runtime, obj);
}
} else {
result.type = "object";
result.description = result.className = "Object";
Expand Down

0 comments on commit d114d7d

Please sign in to comment.