Skip to content

Commit

Permalink
console preview for Error objects
Browse files Browse the repository at this point in the history
Summary: On web, an array of Error objects have previews. This diff brings the parity to RN DevTools

Differential Revision: D61243518
  • Loading branch information
EdmondChuiHW committed Aug 13, 2024
1 parent 8284587 commit 3b811dc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions API/hermes/cdp/RemoteObjectConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ namespace m = ::facebook::hermes::cdp::message;

constexpr size_t kMaxPreviewProperties = 10;

static std::string abbreviateString(const std::string &str) {
const std::string::size_type kMaxLength = 100;
const std::string kEllipsis = "";
if (str.length() <= kMaxLength) {
return str;
}

return str.substr(0, kMaxLength - 1) + kEllipsis;
}

static bool isObjectInstanceOfError(
const jsi::Object &obj,
facebook::jsi::Runtime &runtime) {
Expand Down Expand Up @@ -63,6 +73,11 @@ static m::runtime::PropertyPreview generatePropertyPreview(
preview.subtype = "array";
preview.value = "Array(" +
std::to_string(obj.getArray(runtime).length(runtime)) + ")";
} else if (isObjectInstanceOfError(obj, runtime)) {
preview.type = "object";
preview.subtype = "error";
preview.value = abbreviateString(
obj.getProperty(runtime, "stack").toString(runtime).utf8(runtime));
} else {
preview.type = "object";
preview.value = "Object";
Expand Down

0 comments on commit 3b811dc

Please sign in to comment.