Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 2f09a0f

Browse files
committed
Don't use ObjectInspector for Error grips.
Fixes #960. Since the ErrorRep already provides all the error informations in a nice way (message and stacktrace), there's no benefits being able to inspect the object. Furthermore, when in the console, throwing an Error object gives you a double arrow (first to expand the stack we get from the exception, second is the objectInspector arrow), which is clearly not ideal. Using Rep directly solves these issues.
1 parent 56568f4 commit 2f09a0f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

packages/devtools-reps/src/object-inspector/tests/utils/should-render-roots-in-reps.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const undefinedStubs = require("../../../reps/stubs/undefined");
1111
const gripStubs = require("../../../reps/stubs/grip");
1212
const gripArrayStubs = require("../../../reps/stubs/grip-array");
1313
const symbolStubs = require("../../../reps/stubs/symbol");
14+
const errorStubs = require("../../../reps/stubs/error");
1415

1516
describe("shouldRenderRootsInReps", () => {
1617
it("returns true for a string", () => {
@@ -43,6 +44,12 @@ describe("shouldRenderRootsInReps", () => {
4344
}])).toBeTruthy();
4445
});
4546

47+
it("returns true for Errors", () => {
48+
expect(shouldRenderRootsInReps([{
49+
contents: { value: errorStubs.get("MultilineStackError") }
50+
}])).toBeTruthy();
51+
});
52+
4653
it("returns false when there are multiple primitive roots", () => {
4754
expect(shouldRenderRootsInReps([{
4855
contents: { value: "Hello" }

packages/devtools-reps/src/object-inspector/utils/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const client = require("./client");
88
const loadProperties = require("./load-properties");
99
const node = require("./node");
10-
const { nodeIsPrimitive } = node;
10+
const { nodeIsError, nodeIsPrimitive } = node;
1111
const selection = require("./selection");
1212

1313
const { MODE } = require("../../reps/constants");
@@ -26,8 +26,8 @@ function shouldRenderRootsInReps(roots: Array<Node>) : boolean {
2626

2727
const root = roots[0];
2828
const name = root && root.name;
29-
return nodeIsPrimitive(root)
30-
&& (name === null || typeof name === "undefined");
29+
return (name === null || typeof name === "undefined") &&
30+
(nodeIsPrimitive(root) || nodeIsError(root));
3131
}
3232

3333
function renderRep(

packages/devtools-reps/src/object-inspector/utils/node.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ArrayRep = require("../../reps/array");
99
const GripArrayRep = require("../../reps/grip-array");
1010
const GripMap = require("../../reps/grip-map");
1111
const GripMapEntryRep = require("../../reps/grip-map-entry");
12+
const ErrorRep = require("../../reps/error");
1213

1314
const MAX_NUMERICAL_PROPERTIES = 100;
1415

@@ -208,6 +209,12 @@ function nodeIsBlock(
208209
return getType(item) === NODE_TYPES.BLOCK;
209210
}
210211

212+
function nodeIsError(
213+
item: Node
214+
) : boolean {
215+
return ErrorRep.supportsObject(getValue(item));
216+
}
217+
211218
function nodeHasAccessors(item: Node) : boolean {
212219
return !!getNodeGetter(item) || !!getNodeSetter(item);
213220
}
@@ -811,6 +818,7 @@ module.exports = {
811818
nodeIsBucket,
812819
nodeIsDefaultProperties,
813820
nodeIsEntries,
821+
nodeIsError,
814822
nodeIsFunction,
815823
nodeIsGetter,
816824
nodeIsMapEntry,

0 commit comments

Comments
 (0)