2013-06-11 1 views
4

다음 코드를 사용하여 longjohn을 사용하여 잘못된 스택 추적을 얻고 있습니다. firstfunction에서 호출되는 setTimeout을 보여주고 있지만, 실제로는 firstfunction이 실행되기 전에 프로그램이 충돌하고 있습니다.nodejs에서 longjohn을 사용할 때 스택 트레이스가 잘못됨

은 내가 여기에 티켓을 만든 https://github.com/mattinsler/longjohn/issues/16

var longjohn = require("longjohn"); 

setTimeout(function() { 
    throw new Error(); 
}, 10); 


setTimeout(function() { 
    firstfunction(); 
}, 10000); 


var firstfunction = function() { 
    setTimeout(function() { 
     console.log("First function"); 
    }, 10); 
} 

스택 트레이스

/home/jeevan/node_js/node_modules/longjohn/dist/longjohn.js:181 
     throw e; 
      ^
Error 
    at firstfunction (/home/jeevan/node_js/longjohn.js:11:11) 
    at listOnTimeout (timers.js:110:15) 
--------------------------------------------- 
    at Object.<anonymous> (/home/jeevan/node_js/longjohn.js:10:1) 
    at Module._compile (module.js:456:26) 
    at Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Module._load (module.js:312:12) 
    at Module.runMain (module.js:497:10) 
    at startup (node.js:119:16) 
    at node.js:901:3 

내 질문이 그것을 해결하는 방법에 문제가 될 수있는 것입니다.

답변

1

longjohn도 발생하지 않습니다.

나는 이유를 정확하게 모르겠지만, 당신이 당신의 콜백의 이름을 지정하는 경우, 그것은 작동 더 나은 :

/private/tmp/node_modules/longjohn/dist/longjohn.js:181 
     throw e; 
      ^
Error 
    at MyFirstTimeoutCallback (/private/tmp/lj.js:4:9) <-- much better! 
    at listOnTimeout (timers.js:110:15) 
--------------------------------------------- 
    at Object.<anonymous> (/private/tmp/lj.js:3:1) 
    at Module._compile (module.js:456:26) 
    at Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Module._load (module.js:312:12) 
    at Module.runMain (module.js:497:10) 
    at startup (node.js:119:16) 
    at node.js:901:3 

편집 :은 다음과 같습니다

setTimeout(function MyFirstTimeoutCallback() { 
    throw new Error(); 
}, 10); 
... 

이 다음 역 추적을 생성 노드 0.10에 버그가 도입되었습니다 (어딘가). 내가 0.8.23로 테스트 할 때, 괜찮아 보이는 :

timers.js:103 
      if (!process.listeners('uncaughtException').length) throw e; 
                    ^
Error 
    at Object.<anonymous> (/private/tmp/lj.js:4:9) <-- correct 
    at list.ontimeout (timers.js:101:19) 
    ... 

(bug report)

편집 # 2 :는 V8에서 확인 된 버그 (링크 된 버그 리포트 참조).

관련 문제