Skip to content

console.error enhancement #4452

Description

@DylanPiercey

I'm not sure exactly how this works and if this is the right place to raise the issue but:

In the browser (chrome)

console.error(new Error);

// Logs the error and an expandable stack trace.
Error(…)
    (anonymous function) @ VM297:2
    InjectedScript._evaluateOn @VM174:878
    InjectedScript._evaluateAndWrap @ VM174:811
    InjectedScript.evaluate @ VM174:667

In node:

console.error(new Error)
[Error]

// To properly show the stack trace I would have to console.error the stack.
// In the browser this causes the stack to be visible twice.
console.error((new Error).stack)

Is it possible to make it so that node will automatically add stack traces on console.error?

Activity

  1. added
    consoleIssues and PRs related to the console subsystem.
    feature requestIssues requesting new Node.js features.
    on Dec 28, 2015
  2. julianduque commented on Jan 7, 2016

    @julianduque
    Contributor

    I like this suggestion

  3. zeusdeux commented on Jan 8, 2016

    @zeusdeux
    Contributor

    This will impact behaviour of console.warn as well since in the browser, even that prints the stack trace.
    Also, so does console.log in chrome/firefox/etc.

    So, from what I gather, it's the way util.format handles Error objects that needs to change.

  4. evanlucas commented on Jan 8, 2016

    @evanlucas
    Contributor

    I always forget to add the check for err.stack || err and it drives me nuts. I would be +1 on this, but it would be a semver-major change.

  5. targos commented on Jan 8, 2016

    @targos
    Member

    I would also like this, but on the other hand I'm sure there are a lot of libraries out there that use console.error to output text to stderr (I often do it myself in my utility scripts) so it would definitely be semver-major.

  6. evanlucas commented on Jan 8, 2016

    @evanlucas
    Contributor

    Yea I think it should be a change to util.inspect though for Errors. I think that would make the change less breaking to the ecosystem (although still a major change)

  7. zeusdeux commented on Jan 8, 2016

    @zeusdeux
    Contributor

    I agree that the change should be in util.inspect. The way Errors are displayed could be changed in formatError.

    Edit: I can pick this up and make the changes in formatError if someone hasn't already picked this up.
    Edit 2: Had some time so got it done.

  8. GeorgeBailey commented on Jan 8, 2016

    @GeorgeBailey

    Certainly util.inspect is the right place. +1 this change for the next major version.

  9. added a commit that references this issue on Apr 2, 2016
    ed163e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    consoleIssues and PRs related to the console subsystem.feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions