diff --git a/API/hermes/cdp/RemoteObjectConverters.cpp b/API/hermes/cdp/RemoteObjectConverters.cpp index afeb206eb1c..355f087b08a 100644 --- a/API/hermes/cdp/RemoteObjectConverters.cpp +++ b/API/hermes/cdp/RemoteObjectConverters.cpp @@ -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, @@ -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";