GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: Handle null prototype on inspect by antsmartian · Pull Request #22331 · nodejs/node

Conversation

@antsmartian

@antsmartian antsmartian commented Aug 15, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes : #22141

The implementation and texts are taken from the discussion over here:
#22141 (comment), #22141 (comment)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Aug 15, 2018
antsmartian
antsmartian commented Aug 15, 2018
View reviewed changes
Comment thread test/parallel/test-util-inspect.js Outdated

@antsmartian antsmartian Aug 15, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to remove this test case as this we are checking the message for both cases (with prototype and without prototype). So it was failing with this change. May be I need to do the same test case outside this loop?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Aug 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these tests should work as before if we detect a null prototype on each of these data types. So the test has to be rewritten anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@antsmartian antsmartian changed the title util: Handle null prototype on inspecting util: Handle null prototype on inspect Aug 15, 2018
@jasnell
jasnell requested a review from BridgeAR August 15, 2018 14:08
BridgeAR
BridgeAR reviewed Aug 15, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start but it should not only check for objects but for any type that we explicitly test for and mark it as having a null prototype.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-util-inspect.js Outdated

@BridgeAR BridgeAR Aug 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these tests should work as before if we detect a null prototype on each of these data types. So the test has to be rewritten anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@TimothyGu

TimothyGu commented Aug 16, 2018

Copy link
Copy Markdown
Member

I think this solves the superficial case of #22141 where a prototype is null, but not the general problem of deepEqual that we are not displaying the actual reason why the assertion fails. I am particularly not too great of a fan of special casing null.

My 2¢.

devsnek reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian

antsmartian commented Aug 16, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@TimothyGu Yes, but when using strictEqual (or any other assert) we get the appropriate error message when the assertion fails, for example with this patch we get:

AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
+ actual - expected

+ [Object: null prototype] {}
- {}

I'm not sure, what do you mean by:

but not the general problem of deepEqual that we are not displaying the actual reason why the assertion fails

Am I missing something here?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented Aug 16, 2018

Copy link
Copy Markdown
Member

@antsman whatever changes you make here should be made to assertion, not inspection, is Timothy's point. I feel the same way.

antsmartian reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian

antsmartian commented Aug 16, 2018

Copy link
Copy Markdown
Contributor Author

@devsnek Ok got it. @BridgeAR thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian

antsmartian commented Aug 16, 2018

Copy link
Copy Markdown
Contributor Author

I guess the real problem here is that, when assert fails with null prototype we are not displaying the right error message (no indication that the object had null prototype). Looking at the source code, I see when there is a assert failure, we do call inspect to build up the diff for the error message. If i'm understanding it correctly, then I feel inspect is the right place to handle this, because it doesn't seems to be an assert issue.

May be I'm wrong here too. Open for thoughts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Aug 17, 2018

Copy link
Copy Markdown
Member

@TimothyGu @devsnek for me this is not about assert but about the general handling of null prototypes. I would like to know if the object of kind xyz has a prototype or not. Currently util.inspect does not distinguish these cases but IMO that should be the case.

> {}
{}
> Object.create(null)
{} // I would like to know that this is a different object than the one above.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented Aug 23, 2018

Copy link
Copy Markdown
Member

I would still say that a solution that works for all prototypes rather than special casing null – even in util.inspect() – is the way to go.

BridgeAR and antsmartian reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Aug 23, 2018

Copy link
Copy Markdown
Member

@TimothyGu that is the plan. Currently all prototypes are handled in inspect besides the null prototype.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented Aug 23, 2018

Copy link
Copy Markdown
Member

For reference, Chrome DevTools use a pseudo-__proto__ property for such purposes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian

antsmartian commented Aug 23, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR @TimothyGu Just an update. I'm working on the same for handling all prototypes. Will update the PR in a day or two.. :)

TimothyGu and BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu TimothyGu added the wip Issues and PRs that are still a work in progress. label Aug 23, 2018
@antsmartian
antsmartian force-pushed the util_proto branch 2 times, most recently from b6fccaa to 7ddca64 Compare August 25, 2018 11:36
@antsmartian

antsmartian commented Aug 25, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@BridgeAR I have implemented the check on all the types. Can you please have a look at it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian
antsmartian force-pushed the util_proto branch from 7ddca64 to cd98c73 Compare August 25, 2018 11:48
BridgeAR
BridgeAR reviewed Aug 25, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already looking really good! Thanks a lot for looking into it!

Just a few comments and we should make sure the null prototype is also printed in case a tag exists but no constructor.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-util-inspect.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a typo after SharedArrayBuffer?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@antsmartian antsmartian Aug 25, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed all other comments, but I couldn't able to see any typo 🤔 Sorry could you please explain me, whats wrong here? cc @BridgeAR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

antsmartian reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread test/parallel/test-util-inspect.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add https://github.com/nodejs/node/blob/cd98c735e879e1218b1c8514ab4218efa841bba4/test/parallel/test-util-inspect.js#L1616-L1620 as well. Otherwise important things would not be tested anymore.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-util-inspect.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please also add Arrays, Dataviews and ArrayBuffers? Errors, Dates and regular expressions should be handled in a different PR as they do not show subclassing at all and that should be fixed as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inline this check into the getPrefix check. That way the code should be simpler and pretty straight forward.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@antsmartian antsmartian Aug 25, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thought about it. Will work on that and update the PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@antsmartian
antsmartian force-pushed the util_proto branch from cd98c73 to 09c796c Compare August 25, 2018 15:57
BridgeAR
BridgeAR reviewed Aug 25, 2018
View reviewed changes
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the changes the types have to be 'ArrayBuffer' and 'SharedArrayBuffer' (without the whitespace at the end).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-util-inspect.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

antsmartian reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should now be obsolete.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

antsmartian reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value has a prototype, we do not have to search for it anymore. Therefore it would be best to write this as:

const clazz = Object.getPrototypeOf(value) || findTypedConstructor(value) || clazzWithNullPrototype(Uint8Array, 'Uint8Array')

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@antsmartian antsmartian Aug 26, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly. If we write like the following:

const clazz = Object.getPrototypeOf(value) || findTypedConstructor(value) || clazzWithNullPrototype(Uint8Array, 'Uint8Array')

when there is no prototype, then findTypedConstructor will definitely return the typed array constructor. So we won't reach clazzWithNullPrototype (when there is no prototype) -- missing the subclass stuff.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Aug 28, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, findTypedConstructor should always return the actual type.

Therefore it should likely be:

let clazz = Object.getPrototypeOf(value);
if (!clazz) {
  const constructor = findTypedConstructor(value);
  clazz = clazzWithNullProrotype(constructor, constructor.name);
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition tests for constructor !== '' so instead of testing in another if for the other case, we can just move the code above below this if. In that case we already know, that the constructor is an empty string and don't have to check again.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@antsmartian antsmartian Aug 26, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is true, but the line:

return `[${fallback}: null prototype] `;

definitely needs a check whether a constructor is empty or not.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Aug 28, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is:

if (constructor !== '') {
  ... as before ...
}
if (tag !== '' && fallback !== 'tag') {
  return `[${fallback}: null prototype] [${tag}] `;
} 
return `[${fallback}: null prototype] `;

That way we are sure the constructor is definitely empty.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@antsmartian

antsmartian commented Aug 28, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR Sorry to trouble you, may be you missed my last comments? :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian
antsmartian force-pushed the util_proto branch from 09c796c to 9dc530c Compare August 28, 2018 17:45
@antsmartian

antsmartian commented Aug 29, 2018

Copy link
Copy Markdown
Contributor Author

Ping @BridgeAR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR approved these changes Aug 29, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great work :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit: adding the line seems obsolete.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/util.js Outdated

@BridgeAR BridgeAR Aug 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit: I would remove the newline here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-util-inspect.js Outdated

@BridgeAR BridgeAR Aug 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this now seems to be a duplicated entry with the test below. Since the test below tests more than this one, it would be best to move this entry (or just keep it).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR BridgeAR removed the wip Issues and PRs that are still a work in progress. label Aug 29, 2018
@BridgeAR

BridgeAR commented Aug 29, 2018

Copy link
Copy Markdown
Member

CI https://ci.nodejs.org/job/node-test-pull-request/16867/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian
antsmartian force-pushed the util_proto branch from 9dc530c to 9112c00 Compare August 30, 2018 14:53
@antsmartian

antsmartian commented Sep 25, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR Seems like following this c600a3c , we got a conflict. So I need to move the logic to lib/internal/util/inspect.js

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung mentioned this pull request Sep 25, 2018
CI failures: 20180925 nodejs/reliability#17
Closed
antsmartian and others added 3 commits September 27, 2018 19:42
@antsmartian
util: Handle null prototype on inspect
96fdc40
@BridgeAR @antsmartian
util: improve prototype detection in .inspect()
d14c3e6
This makes sure the `null` prototype is always detected properly.
@antsmartian
util: Move handling null logic to inspect file
215700c
@antsmartian
antsmartian force-pushed the util_proto branch from 4f52f0f to 215700c Compare September 27, 2018 14:45
@antsmartian

antsmartian commented Sep 27, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR I have moved the logic to internal/inspect.js. Please check and see if we can merge this.

BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR approved these changes Sep 27, 2018
View reviewed changes
@antsmartian

antsmartian commented Oct 1, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR Anything else blocking this PR from getting merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Oct 2, 2018
@antsmartian @BridgeAR
util: handle null prototype on inspect
f4e4ef5
This makes sure the `null` prototype is always detected properly.

PR-URL: nodejs#22331
Fixes: nodejs#22141
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
@BridgeAR

BridgeAR commented Oct 2, 2018

Copy link
Copy Markdown
Member

Landed in f4e4ef5 🎉

@antsmartian thanks for sticking to it and being patient!

antsmartian reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR closed this Oct 2, 2018
@targos targos added the backport-requested-v10.x label Oct 3, 2018
@antsmartian
antsmartian deleted the util_proto branch October 17, 2018 17:17
@antsmartian

antsmartian commented Oct 19, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR Sorry to ping on the closed thread. If you remember, one of the early comments you mentioned that:

Would you please also add Arrays, Dataviews and ArrayBuffers? Errors, Dates and regular >expressions should be handled in a different PR as they do not show subclassing at all and that >should be fixed as well.

I was looking to implement for Error this morning. Lets say for this example:

class MyError extends Error {}
new MyError()

// want to print:
MyError
  at . . . 

//but currently prints:
Error:
  at

Also as said in the issue, we need to handle null cases as well (but that should be simple given we have getConstructorName and getPrefix in place). I have a made rough implementation:

diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 4cff372b33..c4e59116f1 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
 function formatError(value) {
+
+  // Preserve the sub-classing info
+  // in Error stack
+  function WrapError(error) {
+    const constructor = getConstructorName(value);
+    const prefix = getPrefix(constructor, '', 'Error').trim();
+
+    this.name = prefix;
+    this.message = error.message;
+
+    const stackStart = error.stack && value.stack.indexOf('\n    at');
+    if (error.stack && stackStart !== -1) {
+      let stack = error.stack;
+      stack = stack.slice(stackStart, stack.length);
+      stack = prefix + (this.message ? `: ${this.message}` : '') + stack;
+      this.stack = stack;
+    } else {
+      this.stack = error.stack;
+    }
+
+    return this;
+  }
+
+  // eslint-disable-next-line no-restricted-syntax
+  value = new  WrapError(value);
+
   return value.stack || errorToString(value);
 }

But looks like stack property shouldn't be mutated at all, just in case of message property was muted (test-internal-error.js does have a test for the same). I was wondering, how we can achieve that 🤔 Because when someone calls util.inspect with error object, I'm not sure how we can find if the message property is muted or not.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Oct 19, 2018

Copy link
Copy Markdown
Member

@antsmartian feel free to chat with me on IRC (even though I am not always around).

It is indeed not a good idea to mutate the input at all. Instead, we should be able to just create the output as we expect it to look like and we only change to change a single string: the stack after accessing it.

We also already have the constructor name and don't have to get it again.

So it should be similar to:

function formatError(value, constructorName) {
  if (value.stack) {
    let stack = value.stack;
    if (!stack.startsWith(constructorName)) { // Note: this check is likely not sufficient.
      return stack.replace(..., constructorName);
    }
    return stack;
  }
  return errorToString(value);
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@antsmartian

antsmartian commented Oct 19, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@BridgeAR Thanks. (can you just tell me your IRC handle, I searched for bridgear, doesn't look like its correct)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

antsmartian added a commit to antsmartian/node that referenced this pull request Oct 30, 2018
@antsmartian abelginrayen
util: handle null prototype on inspect
a39f341
  This makes sure the  prototype is always detected properly.

  PR-URL: nodejs#22331
  Fixes: nodejs#22141
  Reviewed-By: Ruben Bridgewater <[email protected]>
  Reviewed-By: Matteo Collina <[email protected]>
  Reviewed-By: James M Snell <[email protected]>
  Reviewed-By: John-David Dalton <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 12, 2018
@antsmartian @MylesBorins
util: handle null prototype on inspect
3df083c
This makes sure the  prototype is always detected properly.

Backport-PR-URL: #23655
PR-URL: #22331
Fixes: #22141
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
@MylesBorins MylesBorins added backported-to-v10.x and removed backport-requested-v10.x labels Nov 12, 2018
@codebytere codebytere mentioned this pull request Nov 27, 2018
v10.13.1 proposal #24675
Closed
rvagg pushed a commit that referenced this pull request Nov 28, 2018
@antsmartian @rvagg
util: handle null prototype on inspect
ef72b01
This makes sure the  prototype is always detected properly.

Backport-PR-URL: #23655
PR-URL: #22331
Fixes: #22141
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 29, 2018
@antsmartian @MylesBorins
util: handle null prototype on inspect
90014b6
This makes sure the  prototype is always detected properly.

Backport-PR-URL: #23655
PR-URL: #22331
Fixes: #22141
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
@codebytere codebytere mentioned this pull request Nov 29, 2018
v10.14.2 proposal #24727
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@jasnell jasnell jasnell approved these changes
@BridgeAR BridgeAR BridgeAR approved these changes
@TimothyGu TimothyGu Awaiting requested review from TimothyGu
@addaleax addaleax Awaiting requested review from addaleax
+1 more reviewer
@jdalton jdalton jdalton approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@antsmartian @TimothyGu @devsnek @BridgeAR @jdalton @mcollina @jasnell @MylesBorins @targos @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.