Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug console in NodeJs does not display value returned via util.inspect.custom or toString #46829

Closed
leoseccia opened this issue Mar 28, 2018 · 8 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@leoseccia
Copy link

Environment details

  • VSCode Version: 1.21.1
  • OS Version: Win7 x64
  • Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce

  1. Create the following javascript file in VSCode
const util = require('util');

class SomeObject{
    constructor(){
        this._varA = "some text";
        this._varB = 12345;
        this._varC = "some more text";
        this._varD = true;
        this._varE = 0.45;
    }

    [util.inspect.custom](depth, options) {
        return this.toString();
    }

    toString(){
        return "custom textual rapresentation of my object";
    }
}

var array = [];

array.push(new SomeObject());
array.push(new SomeObject());
array.push(new SomeObject());

console.log(array);
  1. Run the code in debug mode and look at the debug console

Actual

This is displayed

Expected

In my opinion, this is not quite right. The inspect method is invoked as you would expect but the debug textual representation for the object instance is not shown to be the custom return string value.

Ideally, I believe the debug console should show the summary value of the object as: SomeObject { "custom textual rapresentation of my object" } while still providing the ability to drill down into the object (as it already does).

Additional Info

This started as a question on StackOverflow: https://stackoverflow.com/questions/49365663/how-to-change-string-representation-of-objects-in-nodejs-debug-console-view

@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues bug Issue identified by VS Code Team member as probable bug and removed debug Debug viewlet, configurations, breakpoints, adapter issues labels Mar 28, 2018
@roblourens
Copy link
Member

Calling util.inspect to generate the preview when the object has overridden util.inspect.custom is a good idea.

I don't think we want to use it for every preview. Our preview should give a short high level view of the properties of an object, but util.inspect recurses and writes out every property of the object, and returns a multiline string where in the debug console, we can only show a single line.

@leoseccia
Copy link
Author

leoseccia commented Mar 28, 2018

@roblourens - anyway to override that one line would be great... I was not sure about inspect either. Maybe hooking on a toString() method if it exists would work better? I think that is the way it works in .NET + VisualStudio.

@sveitser
Copy link

sveitser commented Mar 26, 2019

I'm wondering if anyone has found a way/workaround for this. I'm debugging code that uses bignumber.js and it's quite tricky to read the unformatted representations.

image

@blitzmann
Copy link

Also looking for a solution. As a Python turned TypeScript dev, I'm sorely missing Python's __repr__ magic method and PyCharms ability to display that as the textual representation of an object, if available. Having something similar in VSCode would be greatly beneficial for objects that have a bunch of properties, but there's a way to format some of them to give a good high-level view of what it is. When I have an array of over 200 object, this would be invaluable.

Perhaps a setting in VS Code that allow VSCode to call the toString method on an object to display in that one line?

@weinand
Copy link
Contributor

weinand commented Aug 13, 2019

please see the related item #26234 which we plan to investigate in the August timeframe.

@isidorn
Copy link
Contributor

isidorn commented Jul 30, 2020

I believe this works fine with latest vscode insiders.
If you still see this not working please let me know and I will reopen

@isidorn isidorn closed this as completed Jul 30, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2020
@weinand
Copy link
Contributor

weinand commented Nov 4, 2020

@connor4312 our investigation in #26234 showed that Custom Object Formatters need to be implemented by individual debug extensions. Therefore I'm reopening this issue for JavaScript. Maybe you have already some insights in this topic...

@weinand weinand reopened this Nov 4, 2020
@weinand weinand assigned connor4312 and unassigned roblourens, weinand and isidorn Nov 4, 2020
@weinand weinand removed the bug Issue identified by VS Code Team member as probable bug label Nov 4, 2020
@weinand weinand removed this from the On Deck milestone Nov 4, 2020
@connor4312
Copy link
Member

connor4312 commented Nov 4, 2020

Thanks for the tag. Merging this into #102181 which is being revivified by backlog issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

7 participants