GithubHelp home page GithubHelp logo

andreasmadsen / trace Goto Github PK

View Code? Open in Web Editor NEW
194.0 10.0 18.0 168 KB

Creates super long stack traces

Home Page: https://trace.js.org

License: MIT License

JavaScript 96.40% R 3.60%
trace javascript debugging asynchronous stack-traces

trace's Introduction

trace Build Status

Creates super long stack traces

See https://trace.js.org for examples.

Trace only works with node.js v8.x and newer. Use npm install trace@^2 for node.js v6 and v4.

How

npm install trace --save
node --stack_trace_limit=100 -r trace debug-me.js

This will provide a very long stack trace, if you are not interested in node internal lines, take a look at clarify.

npm install clarify --save
node --stack_trace_limit=100 -r trace -r clarify debug-me.js

For specific examples see https://trace.js.org.

Found a bug?

I encourage you to file any bugs you may find, even if you can't reduce the issue to only involve nodecore modules. I will then use all my power to fix it.

I want this module to be the best and most trusted async trace module ever!

trace's People

Contributors

amilajack avatar andreasmadsen avatar cspotcode avatar maritz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trace's Issues

Add an `install` method

Would it be a good idea to add an install method that performs asyncHook.createHook() and modifies Error.prepareStackTrace (through stack-chain) instead of automatically doing it when the module is required?

It can already be done right now by conditionally calling require() but this might be problematic when using ES modules and import (until dynamic imports become more supported).

Also it goes against the assumption some users may have, that when they require() a module, it only defines functions and constants and does not perform significant logic.

A good compromise to support both behaviors is often to add a register.js file that performs the modification automatically, and offer an install method in the main export.

There could also be an uninstall method.

Add GitHub releases

First, thanks for this project, this is very helpful!

Would it be possible to git tag the versions, so that GitHub releases are automatically created? This is helpful when users are subscribing to this repository using a RSS reader. Thanks!

Memory leak

Memory leak!

Hello!
Not sure if it is done on purpose, and it is by-design, but I encountered a huge memory leak using your library with express.js.

I created a tiny PoC for you to check it out. https://github.com/Sprit3Dan/mem-leak

The way it could be reproduces is to make the callback for the express path asynchronous by adding the async keyword.

Here are the charts for heap used per ~1k queries.

If you add the library:

image

If not:

image

Guess many people could be stuck at this situation, when using you lib.
Hope you find this ticket useful :)

build failing

I just installed trace and included it at the top of my code and I get a dependency error from your module:

Error: Cannot find module 'tracing'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (<application>/node_modules/trace/trace.js:2:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

New AsyncListener API

Just FYI, the API will be changing in the next release. From this:

process.addAsyncListener(function() { }, {
  before: function() { },
  ...
});

to this:

process.addAsyncListener({
  create: function() { },
  before: function() { },
  ...
});

This way create() is optional.

As a side note, I've found it useful to strip out the lines at process.runAsyncQueue (node.js:324:37) since they occur so often. Mainly for readability.

Nice work though. Glad to see you were able to get the long stack traces correct. :)

Make it work again with 4.4.3 LTS again

According to the history of the project (and also the readme) I assume the module once worked fine with the 4.x branch of Node.js - so are there any plans to make it work with the LTS (again)?

Error security context

Security context: 0x161441b1e6e1
2: /* anonymous */ [0x1447d0c19e49] [/app/node_modules/trace/trace.js:~18] [pc=0x374422fea67d](this=0x1447d0c49349 <JSArray[1]>,error=0x1058848d7d91 ,frames=0x1058848d83b1 <JSArray[9]>)
3: emitInitNative(aka emitInitNative) [0x184c0c89b119] [internal/async_hooks.js:~131] [pc=0x3744233...

Compatibility with node ^7.0

When running this module with node ^7.0 yarn gives the following warning (npm ignores it and installs succesfully):

error [email protected]: The engine "node" is incompatible with this module. Expected version "^4.5 || ^6.0".

The dreaded "throwing after await"

This might be completely expected, I'm not completely up-to-date on the state of node.js, but:

Repro steps

git clone https://github.com/fasterthanlime/async-test && cd async-test
npm i
npm start

Versions

$ node --version
v8.0.0

$ npm list
[email protected] C:\msys64\home\amwenger\Dev\async-test
`-- [email protected]
  `-- [email protected]

Output

=================================
 Throwing first thing
=================================
Full stack trace:
Error: throwing first thing
    at cherrypie (C:\msys64\home\amwenger\Dev\async-test\index.js:12:13)
    at binomial (C:\msys64\home\amwenger\Dev\async-test\index.js:14:40)
    at abacus (C:\msys64\home\amwenger\Dev\async-test\index.js:15:38)
    at main (C:\msys64\home\amwenger\Dev\async-test\index.js:16:22)
    at Object.<anonymous> (C:\msys64\home\amwenger\Dev\async-test\index.js:34:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
    at <anonymous>
    at checkStack (C:\msys64\home\amwenger\Dev\async-test\index.js:38:5)
    at main (C:\msys64\home\amwenger\Dev\async-test\index.js:16:11)
    at Object.<anonymous> (C:\msys64\home\amwenger\Dev\async-test\index.js:34:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3


=================================
 Throwing after await
=================================
Full stack trace:
Error: after timeout
    at cherrypie (C:\msys64\home\amwenger\Dev\async-test\index.js:26:13)
    at <anonymous>
    at <anonymous>
    at checkStack (C:\msys64\home\amwenger\Dev\async-test\index.js:38:5)
    at main (C:\msys64\home\amwenger\Dev\async-test\index.js:30:11)
    at <anonymous>
    at runMicrotasksCallback (internal/process/next_tick.js:86:5)
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)
    at Function.Module.runMain (module.js:607:11)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3


didn't see abacus, bailing

Expected output

In the second trace, something like:

<snip>
Error: after timeout
    at cherrypie (C:\msys64\home\amwenger\Dev\async-test\index.js:26:13)
    at binomial (path:line)
    at abacus (path:line)
<snip>

I get this error when running node 4.4.5

I get this error when running node 4.4.5

/node_modules/async-hook/async-hook.js:106
  asyncWrap.setupHooks({
            ^
TypeError: init callback must be a function
    at TypeError (native)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

AsyncWrap init hook threw

Sometimes I get the error:

FATAL ERROR: node::AsyncWrap::AsyncWrap init hook threw
Aborted

Node v4.2.4 & trace v2.2.0.

Swallowing errors with Axios

I'm trying to use Axios to make http calls and have the following code.

const axios = require('axios')

async function main () {
  await axios(`https://example.com/xxxxxxxx`)
}

main()

It of course fails with a 404 as expected with absolutely no useful information.

(node:3179) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (/tmp/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/tmp/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/tmp/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:322:22)
    at endReadableNT (_stream_readable.js:1187:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:3179) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3179) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

So let's put in trace.

require('trace');
const axios = require('axios')

async function main () {
  await axios(`https://example.com/xxxxxxxx`)
}

main()

This still doesn't give us anything useful.

(node:3184) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (/tmp/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/tmp/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/tmp/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:322:22)
    at endReadableNT (_stream_readable.js:1187:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:3184) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

So I looked into the Axios codebase to see what is going on and discovered they have a createError function. I edited the following...

# node_modules/axios/lib/core/createError.js
var enhanceError = require('./enhanceError');

module.exports = function createError(message, config, code, request, response) {
  var error = new Error(message);
  error.stack += ''; // <------ I INSERTED THIS LINE
  return enhanceError(error, config, code, request, response);
};

Note the only thing I changed was effectively running the setter for stack. error.stack += '';

Again I get nothing. BUT when I install clarify I finally get the information I wanted:

require('trace');
require('clarify');

const axios = require('axios')

async function main () {
  await axios(`https://example.com/xxxxxxxx`)
}

main()
(node:3229) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (/tmp/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/tmp/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/tmp/node_modules/axios/lib/adapters/http.js:236:11)
    at Axios.request (/tmp/node_modules/axios/lib/core/Axios.js:61:23)
    at Axios.request (/tmp/node_modules/axios/lib/core/Axios.js:50:25)
    at wrap (/tmp/node_modules/axios/lib/helpers/bind.js:9:15)
    at main (/tmp/index.js:7:9)
    at Object.<anonymous> (/tmp/index.js:10:1)
(node:3229) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3229) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I need both clarify and to touch the .stack inside Axios to make this work.

I don't mind having to keep clarify installed, that's all good and I'd be using it anyway. But obviously touching Axios or any other libraries to touch the .stack seems weird.

Am I crazy? Is this a bug and known? Is there anything I can do?

Thanks and amazing projects btw.

Failing on node 0.12

node_modules/trace/trace.js:3
const chain = require('stack-chain');
^^^^^
SyntaxError: Use of const in strict mode.

Can you flag an older version in npm, that does not require ES2015, to be installed on node <= 0.12.x?

Design issue

This module asumes that every async operation is monkey-patched by async-hook, however there is internal stuff in nodecore there isn't monkey-patched.

The following theoretical workflow is therefor possible:

The current implementation is therefor wrong!.

update

After sleeping some days on this, and fixing some a bug in async-hook and in nodecore, there might not be a bug.

The questing is in the flowing workflow:

event-loop-index: 1         2                      3
          publicA(cb)
                   | --- activeTrace = A -> cb()
          publicB(cb)
                   | --- internalA(cb2)
                                    | ----- activeTrace = B -> cb()

Is it then possible that activeTrace = B could become A. Right now I don't think so. Clearly an extensive is needed.

setTimeout() returns undefined under Node 4 since trace 2.0

console.log(setTimeout(function () {}, 0))
//{ _called: false,
//  _idleTimeout: 1,
//  _idlePrev: 
//   Timer {
//     '0': [Function: listOnTimeout],
//     _idleNext: [Circular],
//     _idlePrev: [Circular],
//     msecs: 1 },
//  _idleNext: 
//   Timer {
//     '0': [Function: listOnTimeout],
//     _idleNext: [Circular],
//     _idlePrev: [Circular],
//     msecs: 1 },
//  _idleStart: 195,
//  _onTimeout: [Function: noop],
//  _repeat: null }

require('trace')

console.log(setTimeout(function () {}, 0))
// undefined

Doesn't really work

In a real app that just fails. Maybe V8 has changed. My code is big, I didn't localize the issue, but.. Please try it in a real app.

P.S. I use Koa.JS

SyntaxError: Use of const in strict mode.

When i try to use this in node v0.10.32 which is old I know. I get this error. Is there no way to use this or something to get a proper trace in node 0.10 ?

const chain = require('stack-chain');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/agirorn/hal.js/backend/spec/helpers/trace.helper.js:1:63)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

Out of memory

A followup to #9, so that we won't forget it.

With the latest trace on, the Node.JS process runs for some time, eats more and more memory, then dies with Out-Of-Memory message.

Dublicated stack trace

Sometimes the stack trace is dublicated this is because an operation there looks like to be asynchronous turns out to be synchronous. I don't have a small example yet, but it could properly be solved by making a positive synchronous check.

Getting "node::AsyncWrap::AsyncWrap init hook threw" error when using 2.0.2

maintainer edit: If you are experiencing this issue, please file a new issue. This is a common error message and can be caused by many different things.

After updating to 2.0.2 (from 2.0.1) I'm getting a FATAL ERROR: node::AsyncWrap::AsyncWrap init hook threw error when using trace.

Tested with node.js versions 4.2.3 and 4.2.4 on windows

Stack Trace makes no sense

I using Node v9.3.0 and the stack traces provided by this module make no sense to me. Here's the example that I'm using:

'use strict';
require('trace');
require('clarify');
Error.stackTraceLimit = 100;

function thing() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            reject(new Error('error'));
        }, 10);
    });
}

async function test() {
    try {
        await thing();
    } catch(err) {
        console.error(err);
    }
}

test();

Here's the call stack that I receive:

Error: error
    at Timeout.setTimeout [as _onTimeout] (C:\projects\test\test.js:9:20)
    at test (C:\projects\test\test.js:16:15)
    at Object.<anonymous> (C:\projects\test\test.js:22:1)
    at test (C:\projects\test\test.js:16:15)
    at Object.<anonymous> (C:\projects\test\test.js:22:1)
    at test (C:\projects\test\test.js:14:20)
    at Object.<anonymous> (C:\projects\test\test.js:22:1)

The first three frames make sense, but the rest is nonsense as far as I can tell.

Wrong stack?

I'm developing and didn't have the time to leave it hanging yet, but got another thing.

Please consider the video here:
http://ilyakantor.ru/screen/2014-09-13_1705.swf

In short, I refresh the page and the stack trace changes. But the control flow is the same. Is it normal?

I'd like to point out: it skips kind of a lot of intermediate middlewares in the stack. Is it intentionally?

Here's the last trace:

    Cannot read property 'token' of undefined
        at res (/js/javascript-nodejs/node_modules/jade/lib/jade.js:175:38)
        at Object.exports.render (/js/javascript-nodejs/node_modules/jade/lib/jade.js:300:10)
        at Object.exports.renderFile (/js/javascript-nodejs/node_modules/jade/lib/jade.js:336:18)
        at Object.render (/js/javascript-nodejs/modules/setup/render.js:131:19)
        at Object.get (/js/javascript-nodejs/hmvc/tutorial/controller/article.js:65:20)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:74:21)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:67:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at exit (/js/javascript-nodejs/node_modules/co/index.js:51:7)
        at Object.next (/js/javascript-nodejs/node_modules/co/index.js:76:18)
        at Object.<anonymous> (/js/javascript-nodejs/node_modules/co/index.js:93:18)
        at Immediate._onImmediate (/js/javascript-nodejs/node_modules/co/index.js:52:14)
        at Connection.start (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:173:29)
        at _connect (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:205:16)
        at /js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:136:15
        at null.<anonymous> (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:133:11)
        at Socket.<anonymous> (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:318:10)
        at Connection.start (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:173:29)
        at _connect (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:205:16)
        at /js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:136:15
        at null.<anonymous> (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:133:11)
        at Socket.<anonymous> (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:318:10)
        at Connection.start (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:173:29)
        at _connect (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:205:16)
        at ConnectionPool.start (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:225:3)
        at Server.connect (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:698:18)
        at Db.open (/js/javascript-nodejs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:278:23)
        at NativeConnection.doOpen (/js/javascript-nodejs/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:56:11)
        at NativeConnection.Connection._open (/js/javascript-nodejs/node_modules/mongoose/lib/connection.js:410:15)
        at NativeConnection.Connection.open (/js/javascript-nodejs/node_modules/mongoose/lib/connection.js:251:8)
        at Mongoose.connect (/js/javascript-nodejs/node_modules/mongoose/lib/index.js:212:15)
        at Object.<anonymous> (/js/javascript-nodejs/modules/config/mongoose.js:21:10)
        at Object.<anonymous> (/js/javascript-nodejs/modules/app.js:13:18)
        at Object.<anonymous> (/js/javascript-nodejs/bin/server:5:13)

P.S. That had both trace and clarify on and stack limit of 1000.

`executionScopeDepth` does not make sense if concurrent async operations

As far as I can tell, executionScopeDepth doesn't really make sense if multiple async operations are happening at once. Rather than being a "depth," it sounds like it represents the total # of active async contexts, right? In an active server, it may never reach 0. Is my interpretation correct?

Error: Conflicting version of stack-chain found

Hi, I'm trying to use this package to get errors when running cucumber.js, but I get Error: Conflicting version of stack-chain found when trying to run them together.

cucumber version 1.3.2

Command: node --stack_trace_limit=100 -r trace .\node_modules\cucumber\bin\cucumber.js .\some\path\to\a.feature -r features

Output:
Error: Conflicting version of stack-chain found
at Object. (C:\redacated\node_modules\stack-chain\index.js:10:11)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:\redacated\node_modules\cucumber\lib\cucumber\runtime\stack_trace_filter.js:2:13)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:\redacated\node_modules\cucumber\lib\cucumber\runtime.js:59:40)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:\redacated\node_modules\cucumber\lib\cucumber.js:14:34)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:\redacated\node_modules\cucumber\bin\cucumber.js:2:16)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

Treating error.stack as immutable?

Hi Andreas,

As you may have seen here and here, if this proposal gets approved errors' stacks will be immutable. If that happens trace will need a redesign.

The main difference would be that the async-trace would have to be stored somewhere else, so printing a trace-enhanced stack trace will require special logic.

A default uncaughtException handler can be set by trace to print the complete errors in node, but special integrations with everything else will be needed. For example, mocha prints stack traces of tests that unexpectedly throw, and would need a trace integration to take advantage of it.

While this alternative design is not as cool as just adding -r trace in front of node, I think it's worth exploring if showing its usefulness can help v8's error-creation hook move forward and have a workable solution for async-traces.

Source map support

Cool library! But, unfortunately seems, that it not support source maps (proper line, column).
Would be awesome to support this stuff.

current uid is a stack

MakeCallback is sometimes called synchronously, thus uid can have multiple values in the same synchronous context.

Support Bluebird coroutines

First up, really love this library + stack-chain! Awesome stuff. I investigated using it in an app I have, but unfortunately I ran into some issues. Here's my problem.

I'm not sure how familiar you are with ES6 generators when used with a promise library that supports them (q / bluebird / others). Basically, instead of CPS-style spaghetti or noisy promise handling code, you can do this:

var promise = require("bluebird");

var gogo = Promise.coroutine(function*() {
    yield someMethodThatReturnsAPromise();
    yield someOtherMethodThatAlsoReturnsAPromise();
    throw new Exception("Omg awesome!");
});

process.nextTick(gogo);

Essentially, it makes async code look synchronous again, and you can actually use try/catch to handle errors that come back from async oeprations. Awesome-sauce.

The problem is that this library follows all of these yielded promises through async ops and back again. As a result, the stack trace for the snippet of code above actually includes stack frames for every single yielded promise. This means that instead of seeing a clean stacktrace from when the co-routine was called up until the error was thrown, we instead see the calls to someMethodThatReturnsAPromise and someOtherMethodThatAlsoReturnsAPromise + any async operations they went through in the trace.

I tried to do some hacky insanity with trace. I added a mark + rewind feature that would snapshot the stack, and then reset the callsites back to the saved ones after each yielded promise was resolved, but there was a bunch of corner cases and it felt really ... wrong. I was wondering, since you wrote this library and have obviously thought through this stuff alot, if you had any ideas about how to handle this?

If this all sounds incoherent, let me know and I can craft up a proper test case for you to play with.

Usage with electron

Thanks for that great product. Is there a way i can use this with electron ?

Memory leak of sorts

Hello, infinitely recursing setTimeout calls will increase the memory usage forever.

Reproduction code: (node 8.9.1)

require('trace');
const memwatch = require('memwatch-ng');

memwatch.on('leak', info => {
    console.log('Memory leak detected.');
    console.log(info);
});

function loop (func) {
    const execute = () => {
        func().then(() => {
            setTimeout(execute, 0);
        });
    };
    execute();
}

console.log(`Stack trace limit is: ${Error.stackTraceLimit}`);

loop(async () => {
    await new Promise(resolve => setTimeout(resolve, 0));
});

I don't suppose there's a way for trace to limit its memory usage? I understand that I'm essentially creating an infinitely long stack trace, but this code does work without trace enabled.

attempting to print the stack results in a TypeError

debug> repl
Press Ctrl + C to leave debug repl
> e = new Error('e')
{ handle: 6,
  type: 'error',
  className: 'Error',
  constructorFunction: { ref: 7 },
  protoObject: { ref: 8 },
  prototypeObject: { ref: 1 },
  properties:
   [ { name: 'stack', attributes: 2, propertyType: 3, ref: 1 },
     { name: 'message', attributes: 2, propertyType: 0, ref: 9 } ],
  text: 'Error: e' }
> e.stack
TypeError: Cannot read property 'slice' of undefined

Recent async-hook update breaks trace on node v4

Hi there โ€“ thanks for trace, it's saved my neck countless times!

I'm running Node LTS (v4) in production, and a recent update to async-hook has meant that calling require('trace') now breaks my app.

I notice that since v1.3.0, async-hook now only supports Node v5. Seeing as this was only a minor semver bump to the async-hook module (despite being a breaking change), that means that trace will depend on the new version, and therefore implicitly requires node v5.

I imagine I'm not the only one running the LTS version of node โ€“ is there a way we can get trace working on v4 as well as v5? Thanks!

Memory leak with clearTimeout

When clearTimeout is called the destroy hook isn't called because setTimeout is monkey patched. clearTimeout will need to be monkey patched as well. This is also an issue with setInterval and setImmediate.

Issue with Node 4

It works correctly with process.nextTick(), setImmediate(), setTimeout(), even errors originating from fs.readFile() but not with http.request().

require('trace')

var request = require('http').request

function main () {
  request({ hostname: '0.0.0.1' }, response => {
    response.pipe(process.stdout)
  })
}

main()
> node index.js
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: connect EINVAL 0.0.0.1:80 - Local (0.0.0.0:0)
    at Object.exports._errnoException (util.js:837:11)
    at exports._exceptionWithHostPort (util.js:860:20)
    at connect (net.js:838:14)
    at net.js:934:9
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)
    at Function.Module.runMain (module.js:477:11)
    at startup (node.js:117:18)
    at node.js:951:3
    at fireErrorCallbacks (net.js:444:15)

As you can see, the stack trace does not reference my code :/

Conflict of stack-trace version with the one from clarify

After I have execute an npm i in a clear folder (without package-lock.json and node_modules) I have start obtaining the error right on the app start

F:\test\node_modules\trace\node_modules\stack-chain\index.js:10
    throw new Error('Conflicting version of stack-chain found');
    ^

Error: Conflicting version of stack-chain found
    at Object.<anonymous> (F:\test\node_modules\trace\node_modules\stack-chain\index.js:10:11)
    at Object.<anonymous> (F:\test\node_modules\trace\trace.js:3:15)

STR:

  1. Create an empty folder
  2. Execute in it npm i clarify trace
  3. Create a file with code
require('clarify')
require('trace')
  1. Execute file

I'm posting this issue in trace repo, while probably it's the clarify that is needed to be updated, because update of trace has lead to this problem

npm: 5.5.1
node: 9.3.0

Bug in net.connect

This module don't collect the stacktrace in the following case:

require('trace');
var net = require('net');

net.connect(24075); // connection refused

TypeError: Cannot read property 'apply' of undefined

hello! something goes awry when i run my tests using trace. i have a branch that is runnable/testable to reproduce the problem here, using good old node test/.

this file is where it's all wired up!

ok 118 run started from new db document event
/long/path/node_modules/trace/node_modules/async-hook/patches/timers.js:50
      callback.apply(this, arguments);
              ^

TypeError: Cannot read property 'apply' of undefined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.