Skip to content

Improve stack traces for exceptions thrown at a top-level #6271

Description

@fresheneesz
  • Version: 5.1.0
  • Platform: Centos 6.x
  • Subsystem: require

When exceptions are thrown at a top level, there's a distinct lack of information as far as how that module was required. If you have a dependency chain where a requires b which requires c, if c throws an exception while building its module, node doesn't tell you about b or a, which can make it difficult to debug things when there are interactions between modules or global variables.

For example, I'm seeing this exception:

Error: Logger not yet initialized! Initialize first!
    at Error (native)
    at init (/home/vagrant/backend/git/node_modules/logger.js:116:19)
    at eval (eval at proto (/home/vagrant/backend/node_modules/proto/proto.js:57:34), <anonymous>:3:39)
    at Object.<anonymous> (/home/vagrant/backend/git/node_modules/security.js:7:31)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

This doesn't tell me what file required security.js, which would be incredibly helpful to me right now in debugging this problem with my code. Also, the part of the stack trace containing internal node stuff is very unlikely to be useful to a developer unless what they're developing is node itself. I want to suggest that a stacktrace like the following be generated instead:

Error: Logger not yet initialized! Initialize first!
    at Error (native)
    at init (/home/vagrant/backend/git/node_modules/logger.js:116:19)
    at eval (eval at proto (/home/vagrant/backend/node_modules/proto/proto.js:57:34), <anonymous>:3:39)
    at Object.<anonymous> (/home/vagrant/backend/git/node_modules/security.js:7:31)
    required by (db.js:4:16)
    required by (utils.js:9:26)
    required by (server.js:21:20)
    required by (appServer.js:3:36)

Activity

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.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions