Skip to content

In IE and window.onerror, stack trace is uninformative #9

Closed
JoeEven opened this Issue Nov 25, 2010 · 8 comments

6 participants

@JoeEven
JoeEven commented Nov 25, 2010

Issue 1:

Run this:

<html><head><script src="stacktrace.js"></script>
<script>
function foo() {
    bar(2);
}
function bar(n) {
    if (n < 2)
        abc();
    bar(n-1);
}
    var lastError;
    try {
        // error producing code
        foo();
    } catch(e) {
       lastError = e;
       // do something else with error
    }

    // Returns stacktrace from lastError!
    alert (printStackTrace({e: lastError}).join('\n'));
</script>
</head>
<body></body>
</html>

Result:

In IE:

{anonymous}([object Error])

printStackTrace(#object)

In FF:

bar(1)@file:///D:/test/javascriptStackTrace/testcase1.html:12

bar(2)@file:///D:/test/javascriptStackTrace/testcase1.html:13

foo()@file:///D:/test/javascriptStackTrace/testcase1.html:8

@file:///D:/test/javascriptStackTrace/testcase1.html:18

What print in FF is expected while the information in IE is a little simple, but I'm not sure whether I'm using it correctly?

Issue 2:

Run this:

<html><head><script src="stacktrace.js"></script>
<script>
window.onerror = function(msg, file, line) {
    alert(printStackTrace().join('\n'));
    return true;
}

function foo() {
    bar(2);
}
function bar(n) {
    if (n < 2)
        abc();
    bar(n-1);
}
foo();
</script>
</head>
<body></body>
</html>

Result:

In IE (The same as the first case):

{anonymous}([object Error])

printStackTrace(#object)

In FF (The stack trace is different from the first case):

{anonymous}()@file:///D:/test/javascriptStackTrace/stacktrace.js:74

{anonymous}(null)@file:///D:/test/javascriptStackTrace/stacktrace.js:72

printStackTrace()@file:///D:/test/javascriptStackTrace/stacktrace.js:58

{anonymous}("abc is not defined","file:///D:/test/javascriptStackTrace/testcase1.html",17)@file:///D:/test/javascriptStackTrace/testcase1.html:8

In short:

I have two issues, one is the stack trace from IE is different and less information than FF.

Another one is the stack trace become not so helpful if I print stack in window.onerror.

Maybe I have some incorrect method in using your library, or they are already known issue?

Hope for help.

Thanks

@JoeEven
JoeEven commented Nov 25, 2010

Ahh...
I now know that I need to run this in http method, so the stack trace seems a little changed, but still not accurate.
I run the second case in http method, and got:
In IE:
{anonymous}(null)
printStackTrace()
{anonymous}("Object expected","http://localhost/javascriptStackTrace/testcase1.html",17)
bar(1)
bar(1)
bar(1)
bar(1)
bar(1)
bar(1)
bar(1)

In FF:

(?)()@http://localhost/javascriptStackTrace/stacktrace.js:74
run(null)@http://localhost/javascriptStackTrace/stacktrace.js:72
printStackTrace()@http://localhost/javascriptStackTrace/stacktrace.js:58
onerror("abc is not defined","http://localhost/javascriptStackTrace/testcase1.html",17)@http://localhost/javascriptStackTrace/testcase1.html:8

Both of the results are not expected, is there any missing in using your library?

Thanks!

@eriwen
stacktrace.js member
eriwen commented Dec 2, 2010

Joe: I'm looking at this.

Note that there is a bug in the IE implementation when we lose the stack if you use recursion. This is because a construct that I need is overwritten and I cannot get it back.

Regardless, this is not your fault. Your Firefox results for the test are definitely wrong using window.onerror. Stay tuned!

@eriwen eriwen was assigned Apr 10, 2011
@lpena
lpena commented Jan 4, 2012

Hi, I implemented this script, used in IE9 and I found some error (maybe I did something wrong). This is the ex:

So, when the clicked function is called (by an anchor or w/e), the error occurs, the window.error is triggered and the handler is called.
So, printStrackTrace is called and the magic of the script happens, but there is an issue, some how in this part:
while (curr && stack.length < maxStackSize) {
fn = fnRE.test(curr.toString()) ? RegExp.$1 || ANON : ANON;
args = Array.prototype.slice.call(curr['arguments']);
stack[j++] = fn + '(' + this.stringifyArguments(args) + ')';
curr = curr.caller;
}
the curr['arguments'] is null so the Array.prototype.slice.call() fails and everything else stop working.
I managed to fix this by updating this the condition: while (curr && curr['arguments'] && stack.length < maxStackSize)
but I am not an expert on JS, so I wouldn't know if this condition it's good enough or not.
I found that the issue only happens in IE9. In IE 6/7/8 everything works fine, but in IE9 the force error of the script is not getting into the stack (unlike other browsers). Any thoughts? Any advice so I can hack the code a little bit to make it work in all browsers again (sadly I need IE9)
Thanks

@eriwen
stacktrace.js member
eriwen commented Jan 5, 2012

@lpena Yep, that would be good way to fix the error you are seeing.

I would recommend that you do not use printStackTrace() within window.onerror until we have implemented a better way to handle it. Follow this issue and #26 for updates.

@SunboX
SunboX commented Jan 27, 2012

subscribe

@JamesMGreene

Subscribe

@lowbatteries

subscribe

@eriwen eriwen removed the waffle:ready label Oct 7, 2014
@eriwen
stacktrace.js member
eriwen commented Oct 7, 2014

Closing in favor of #96.

@eriwen eriwen closed this Oct 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.