{"id":307,"date":"2009-05-16T19:07:22","date_gmt":"2009-05-17T00:07:22","guid":{"rendered":"http:\/\/www.visophyte.org\/blog\/?p=307"},"modified":"2009-05-16T19:07:22","modified_gmt":"2009-05-17T00:07:22","slug":"better-error-reporting-for-the-mozilla-platform","status":"publish","type":"post","link":"https:\/\/www.visophyte.org\/blog\/2009\/05\/16\/better-error-reporting-for-the-mozilla-platform\/","title":{"rendered":"Better error reporting for the mozilla platform"},"content":{"rendered":"<p><a href=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/old-and-busted-error-reporting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-305\" title=\"old-and-busted-error-reporting\" src=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/old-and-busted-error-reporting.png\" alt=\"old-and-busted-error-reporting\" width=\"806\" height=\"76\" srcset=\"https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/old-and-busted-error-reporting.png 806w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/old-and-busted-error-reporting-600x56.png 600w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/old-and-busted-error-reporting-300x28.png 300w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/a><\/p>\n<p>If you develop for the mozilla platform, you might be used to error messages like the above.\u00a0 (Or you might wish you got error messages like the above&#8230;)\u00a0 An uncaught javascript exception has resulted in a message in the error console as well as some equivalent stdout spew because it&#8217;s a debug build.\u00a0 While any error is better than no error, it doesn&#8217;t exactly narrow down how we got there.<\/p>\n<p>Wouldn&#8217;t it be nice if we got back-traces for these errors?<\/p>\n<p><a href=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/new-error-reporting-hotness.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-306\" title=\"new-error-reporting-hotness\" src=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/new-error-reporting-hotness.png\" alt=\"new-error-reporting-hotness\" width=\"749\" height=\"138\" srcset=\"https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/new-error-reporting-hotness.png 749w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/new-error-reporting-hotness-600x110.png 600w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2009\/05\/new-error-reporting-hotness-300x55.png 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/a><\/p>\n<p>The future is now, people!\u00a0 And it comes in the convenient form of a patch against the 1.9.1 branch, just like you always dreamed!\u00a0 Also, an extension.<\/p>\n<p>Currently (pre-patch), there are basically 3 ways scripting errors can show up in the platform:<\/p>\n<ol>\n<li><a href=\"http:\/\/mxr.mozilla.org\/comm-central\/source\/mozilla\/js\/src\/xpconnect\/idl\/nsIScriptError.idl#47\">nsIScriptError<\/a> instances.\u00a0 These are what show up on the error console.\u00a0 These have information equivalent to a single stack frame.<\/li>\n<li><a href=\"http:\/\/mxr.mozilla.org\/mozilla-central\/source\/xpcom\/base\/nsIException.idl#67\">nsIException<\/a> instances.\u00a0 These can provide a stack in the form of an <a href=\"http:\/\/mxr.mozilla.org\/mozilla-central\/source\/xpcom\/base\/nsIException.idl#51\">nsIStackFrame<\/a> chain (the same thing <a href=\"https:\/\/developer.mozilla.org\/En\/Components.stack\">Components.stack<\/a> gives you).\u00a0 These get converted into nsIScriptError instances when it comes time to report them to the error console.\u00a0 From a stack perspective, only XPConnect produces nsIException instances with stack traces, although you can make your own via <a href=\"https:\/\/developer.mozilla.org\/En\/Components.Exception\">Components.Exception<\/a>.\u00a0 A fundamental limitation of these stack traces is that they are only constructed from live JS call stacks, so if a JS exception has unwrapped its way to the top-level you are out of luck.<\/li>\n<li>JavaScript <a href=\"https:\/\/developer.mozilla.org\/en\/Core_JavaScript_1.5_Reference\/Global_Objects\/Error\">Error<\/a> instances.\u00a0 These have a private super-rich (it even knows arguments!) call-stack that can only be exposed as a string via the non-standard <a href=\"https:\/\/developer.mozilla.org\/en\/Core_JavaScript_1.5_Reference\/Global_Objects\/Error\/stack\">stack<\/a> attribute.\u00a0 XPConnect understands JS error reports (the &#8216;flat&#8217; mechanism by which SpiderMonkey reports errors\/exceptions to C++ code), but it has no clue about exceptions and their Error form of existence.\u00a0 The exceptions in their error report guise are converted into nsIScriptError instances.<\/li>\n<\/ol>\n<p>What the <a href=\"https:\/\/bug493414.bugzilla.mozilla.org\/attachment.cgi?id=377884\">patch<\/a> (on <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=493414\">bug 493414<\/a>) does is:<\/p>\n<ul>\n<li>Introduce an nsIScriptErrorEx interface that extends nsIScriptError to provide a &#8216;location&#8217; attribute like nsIException which is an nsIStackFrame.<\/li>\n<li>Modify nsScriptError to implement the extended nsIScriptErrorEx.\u00a0 Alternatively, I could have made XPConnect&#8217;s nsXPCException class implement nsIScriptError or nsScriptError also implement nsIException or something like that and not introduced nsIScriptErrorEx at all.<\/li>\n<li>Modify all nsIScriptError-creation sites that I care about (I&#8217;m not looking at you, DOM workers) to try and provide or propagate existing nsIStackFrame information.<\/li>\n<li>If a JS stack frame is not available, but an exception is in the form of a JS error, suck the call stack out of it.\u00a0 Theoretically, this should not be a fallback but rather the default case, but it depends on some JS\/XPConnect implementation details I am trying to avoid finding out about for now.<\/li>\n<li>Modify the JS API to provide call stack sucking functionality.<\/li>\n<li>Does various sketchy things to expose XPCJSStack::CreateStack from XPConnect to the error reporters in other modules.\u00a0 If you thought the choice of creating nsIScriptErrorEx was sketchy, welcome to the <a href=\"http:\/\/ascher.ca\/blog\/2009\/03\/27\/downtown-east-side-one-week-in\/\">Downtown East Side<\/a> of dubious patches.\u00a0 I expect there is no chance of it working on Windows because of this, and you may be out of luck on OS X.\u00a0 Behold your comeuppance, popular platforms!<\/li>\n<\/ul>\n<p>What the extension (<a href=\"http:\/\/hg.mozilla.org\/users\/bugmail_asutherland.org\/exmmad\/\">repo<\/a>) does is:<\/p>\n<ul>\n<li>Add an nsIConsoleListener at app-startup that is aware of nsIScriptErrorEx and knows how to generate totally wicked 256-color ANSI escape sequences.<\/li>\n<li>Not expose the stack traces in the error console.\u00a0 The error console is for suckers who don&#8217;t have impossibly fast reflexes and a love of XON\/XOFF flow control.<\/li>\n<li>Only target Thunderbird.\u00a0 Behold your comeuppance, all other mozilla applications!\u00a0 (The extension wizard didn&#8217;t know how to do the thing that makes it work on all xulrunner-based things&#8230;\u00a0 feel free to push a fixed install.rdf to my repo.)<\/li>\n<\/ul>\n<p>I have logged <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=493414\">bug 493414<\/a> to hold the patch and hopefully track the effort moving forward.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you develop for the mozilla platform, you might be used to error messages like the above.\u00a0 (Or you might wish you got error messages like the above&#8230;)\u00a0 An uncaught javascript exception has resulted in a message in the error &hellip; <a href=\"https:\/\/www.visophyte.org\/blog\/2009\/05\/16\/better-error-reporting-for-the-mozilla-platform\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[7,3],"tags":[27,58],"class_list":["post-307","post","type-post","status-publish","format-standard","hentry","category-debugging","category-mozilla","tag-colors","tag-gaudy"],"_links":{"self":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":3,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":310,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions\/310"}],"wp:attachment":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}