Skip to content

Improve util.deprecate #1883

Description

@silverwind

As discussed in IRC recently with @Fishrock123 it would be nice if the deprecation messages contain a bit more info. Particulary I'd like to see

  • filename:linenumber where it happens in userland code. I think this could be parsed off the stack through new Error().stack or similar, suggestions welcome.
  • A prefix like (node) to identify where the messages come from.
  • An flag like -print-all-deprecations to allow more than one print per deprecation to track down all places where it's happening.

Activity

  1. added
    utilIssues and PRs related to the built-in util module.
    on Jun 3, 2015
  2. thefourtheye commented on Jun 3, 2015

    @thefourtheye
    Contributor

    Why do we need the prefix? Can you include an example where it would be useful?

  3. silverwind commented on Jun 3, 2015

    @silverwind
    ContributorAuthor

    Look at line 6 of https://gist.github.com/silverwind/a94589df8e3aae1907e1, do you think an outsider would know what to do based on that message, especially when they happen during something like npm install.

  4. thefourtheye commented on Jun 3, 2015

    @thefourtheye
    Contributor

    Oh okay. You mean (request) ...? That would be good. About the line number and file name, what if the function is called more than once? Whenever user fixes one place he will get deprecation message for other places. Will that be okay?

  5. silverwind commented on Jun 3, 2015

    @silverwind
    ContributorAuthor

    No, I mean a prefix that clearly identifies that the line was logged by node. For multiple prints: I want to keep the functionality to only prince once per function call, of course. Multiple messages should be opt-in through the flag.

  6. Fishrock123 commented on Jun 3, 2015

    @Fishrock123
    Contributor

    👍

  7. thefourtheye commented on Jun 3, 2015

    @thefourtheye
    Contributor

    @silverwind What if other libraries start using util.deprecate? We cannot log (node) in that case, right?

  8. cjihrig commented on Jun 3, 2015

    @cjihrig
    Contributor

    Can't the existing --trace-deprecation flag be used to accomplish your first item? The second item seems a bit unnecessary. +1 to the third item.

  9. silverwind commented on Jun 3, 2015

    @silverwind
    ContributorAuthor

    @thefourtheye I think the intention is to move to an internal module eventually, @vkurchatkin had it moved in a recent PR if I recall correctly.

  10. silverwind commented on Jun 3, 2015

    @silverwind
    ContributorAuthor

    @cjihrig +1 on incorporating multiple prints into --trace-deprecation

  11. vkurchatkin commented on Jun 3, 2015

    @vkurchatkin
    Contributor

    @silverwind no, it is just a helper function. util.deprecate is untouched.

    filename:linenumber where it happens in userland code. I think this could be parsed off the stack through new Error().stack or similar, suggestions welcome.

    This is already available with --trace-deprecation

    A prefix like (node) to identify where the messages come from.

    This could be just a part of the message

    An flag like -print-all-deprecations to allow more than one print per deprecation to track down all places where it's happening.

    +0

  12. silverwind commented on Jun 3, 2015

    @silverwind
    ContributorAuthor

    Right, I didn't realize we were exposing this knowingly in the public API, so it's probably best to include the (node) prefix in the messages itself.

  13. dougwilson commented on Jun 6, 2015

    @dougwilson
    Member

    People who want a public API should probably just use the depd module or similar.

  14. Fishrock123 commented on Jun 6, 2015

    @Fishrock123
    Contributor

    Right, but that doesn't really defer much from the fact that this already is public API.

    The goal of what I was originally talking about was to better highlight spots where user code uses deprecated core APIs. However, I had forgotten about --trace-deprecation, which I think does that.

  15. silverwind commented on Jun 6, 2015

    @silverwind
    ContributorAuthor

    @dougwilson we gotta live with it being public now, or go through a tedious deprecation process of questionable benefit.

    @Fishrock123 I didn't know about it either, but I think the default message should at least include the prefix and line number. The case of deprecation messages during npm install is a good example. These would be just confusing without context.

  16. thefourtheye commented on Jun 6, 2015

    @thefourtheye
    Contributor

    @silverwind The PR has the prefix change already. As we anyway extract the file name and line number from the stack trace, shall I just print them in normal deprecation warning as well?

  17. thefourtheye commented on Jun 7, 2015

    @thefourtheye
    Contributor

    I included a commit in the PR which will be actually printing the location where the deprecated item is used.

  18. silverwind commented on Jul 3, 2015

    @silverwind
    ContributorAuthor

    Fixed by 9cd44bb with what was reasonable to change.

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

    feature requestIssues requesting new Node.js features.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions