From 9b8c7c474e873c7228343beec1785cd470127d0d Mon Sep 17 00:00:00 2001 From: John Bender Date: Sun, 26 Sep 2010 22:47:56 -0700 Subject: [PATCH] added stack track and optional support for javascript-stacktrace --- .gitmodules | 3 ++ examples/app.js | 2 +- examples/index.html | 1 + examples/server.rb | 8 +++-- javascript-stacktrace | 1 + lib/jquery.flawed.js | 18 ++++++++--- spec/dom.html | 1 + spec/unit/spec.js | 71 ++++++++++++++++++++++++------------------- 8 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 .gitmodules create mode 160000 javascript-stacktrace diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..92b1ddf --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "javascript-stacktrace"] + path = javascript-stacktrace + url = http://github.com/emwendelin/javascript-stacktrace.git diff --git a/examples/app.js b/examples/app.js index d701073..c04587e 100644 --- a/examples/app.js +++ b/examples/app.js @@ -1,3 +1,3 @@ jQuery.flawed(function(){ - throw 'foo'; + throw new TypeError('foo'); })(); \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index 01c1afe..64be8dd 100644 --- a/examples/index.html +++ b/examples/index.html @@ -1,6 +1,7 @@ + diff --git a/examples/server.rb b/examples/server.rb index 26671cf..e278ef8 100644 --- a/examples/server.rb +++ b/examples/server.rb @@ -1,5 +1,4 @@ require 'rubygems' -require 'logger' require 'rack' class Rack::Flawed @@ -9,8 +8,11 @@ def initialize(app, opts={}) end def call(env) - if env[@header] - # Log or report exception here + req = Rack::Request.new(env) + + if env[@header] && req.post? + # Log the stacktrack + p req.params end @app.call(env) diff --git a/javascript-stacktrace b/javascript-stacktrace new file mode 160000 index 0000000..630c0c6 --- /dev/null +++ b/javascript-stacktrace @@ -0,0 +1 @@ +Subproject commit 630c0c6d22e881b2af4f031430f1fd4d0e5eaa21 diff --git a/lib/jquery.flawed.js b/lib/jquery.flawed.js index 88d4790..d187bf5 100644 --- a/lib/jquery.flawed.js +++ b/lib/jquery.flawed.js @@ -6,19 +6,29 @@ jQuery.flawed = function (scope){ return function(){ try { scope.apply(this, arguments); - } catch (e) { - var request_params = jQuery.extend(jQuery.flawed.config.ajax, { + } catch (error) { + var stack, request_params; + + if(!(window.printStackTrace == undefined)) + stack = printStackTrace({e: error}); + else + stack = error; + + request_params = jQuery.extend(jQuery.flawed.config.ajax, { data: { url: $(location).attr('href'), - stack: e + message: error.message, + type: error.name, + stack: stack }, + beforeSend: function(request){ request.setRequestHeader(jQuery.flawed.config.header, true); } }); jQuery.ajax(request_params); - throw e; + throw error; } }; }; diff --git a/spec/dom.html b/spec/dom.html index 44ff926..732d534 100644 --- a/spec/dom.html +++ b/spec/dom.html @@ -4,6 +4,7 @@ +