stackdeck 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/stackdeck.rb +8 -0
- data/lib/stackdeck/context.rb +32 -0
- data/lib/stackdeck/exception.rb +25 -0
- data/lib/stackdeck/file_reader.rb +0 -0
- data/lib/stackdeck/frame.rb +101 -0
- data/lib/stackdeck/postgres.rb +68 -0
- data/test/helper.rb +9 -0
- data/test/test_stackdeck.rb +7 -0
- metadata +70 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Matthew Draper
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= stackdeck
|
2
|
+
|
3
|
+
Manages stack traces across language boundaries.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Matthew Draper. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "stackdeck"
|
8
|
+
gem.summary = %Q{Manages stack traces across language boundaries}
|
9
|
+
gem.description = %Q{Manages stack traces across language boundaries.}
|
10
|
+
gem.email = "matthew@trebex.net"
|
11
|
+
gem.homepage = "http://github.com/matthewd/stackdeck"
|
12
|
+
gem.authors = ["Matthew Draper"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "stackdeck #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/stackdeck.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
module StackDeck
|
3
|
+
class Context
|
4
|
+
CONTEXT = 7
|
5
|
+
attr_reader :before_lineno, :before, :line, :after
|
6
|
+
def context_ranges(lines, index)
|
7
|
+
first_line = [index - CONTEXT, 0].max
|
8
|
+
last_line = [index + CONTEXT, lines.size].min
|
9
|
+
|
10
|
+
[first_line...index, (index + 1)..last_line]
|
11
|
+
end
|
12
|
+
def initialize(lines, lineno)
|
13
|
+
if lineno
|
14
|
+
index = lineno - 1
|
15
|
+
pre_range, post_range = context_ranges(lines, index)
|
16
|
+
@before_lineno = pre_range.begin
|
17
|
+
@before = lines[pre_range]
|
18
|
+
@line = lines[index].chomp
|
19
|
+
@after = lines[post_range]
|
20
|
+
else
|
21
|
+
@line = lines.join("\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class File < Context
|
26
|
+
def initialize(filename, lineno)
|
27
|
+
super File.readlines(filename), lineno
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module StackDeck
|
3
|
+
module ExceptionSupport
|
4
|
+
def higher_stack_deck; @higher_stack_deck ||= []; end
|
5
|
+
def stack_deck
|
6
|
+
deck = []
|
7
|
+
deck.concat(internal_stack_deck || []) if respond_to? :internal_stack_deck
|
8
|
+
deck.concat higher_stack_deck
|
9
|
+
deck.concat StackDeck::Frame::Ruby.extract(backtrace) if backtrace
|
10
|
+
deck.compact!
|
11
|
+
StackDeck.apply_boundary!(deck)
|
12
|
+
deck
|
13
|
+
end
|
14
|
+
def copy_ruby_stack_to_deck(ignored_part=caller)
|
15
|
+
upper_backtrace, lower_backtrace = StackDeck.split_list(backtrace, ignored_part)
|
16
|
+
higher_stack_deck.concat StackDeck::Frame::Ruby.extract(upper_backtrace)
|
17
|
+
set_backtrace lower_backtrace
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Exception
|
23
|
+
include StackDeck::ExceptionSupport
|
24
|
+
end
|
25
|
+
|
File without changes
|
@@ -0,0 +1,101 @@
|
|
1
|
+
|
2
|
+
module StackDeck
|
3
|
+
def self.boundary; yield; end
|
4
|
+
|
5
|
+
def self.split_list(full_list, short_list)
|
6
|
+
short_list = short_list.dup
|
7
|
+
upper = full_list.dup
|
8
|
+
lower = []
|
9
|
+
while !short_list.empty? && upper.last == short_list.pop
|
10
|
+
lower << upper.pop
|
11
|
+
end
|
12
|
+
[upper, lower.reverse]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.apply_boundary!(deck)
|
16
|
+
deck.each_with_index do |s, idx|
|
17
|
+
# We don't want any more frames if this is a boundary marker,
|
18
|
+
# *and* the exception didn't occur really close to said boundary.
|
19
|
+
if s.boundary? && idx > 2
|
20
|
+
deck.slice! idx, -1
|
21
|
+
break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Frame
|
27
|
+
attr_accessor :function, :filename, :lineno, :clue
|
28
|
+
def initialize(function, filename, lineno, clue=nil)
|
29
|
+
@function = function
|
30
|
+
@filename = filename unless filename && filename.empty?
|
31
|
+
@lineno = lineno
|
32
|
+
@clue = clue unless clue && clue.empty?
|
33
|
+
end
|
34
|
+
def context
|
35
|
+
@context ||= Context::File.new(filename, lineno) if filename
|
36
|
+
end
|
37
|
+
def same_line?(other)
|
38
|
+
other && self.filename == other.filename && self.lineno == other.lineno
|
39
|
+
end
|
40
|
+
def language; self.class.name.split('::').last; end
|
41
|
+
def boundary?; false; end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"#{filename}:#{lineno}: in `#{function}' [#{language}]"
|
45
|
+
end
|
46
|
+
|
47
|
+
class Ruby < Frame
|
48
|
+
def self.parse(str)
|
49
|
+
if str =~ /(.*?):(\d+)(:in `(.*)')?/
|
50
|
+
new($4, $1, $2.to_i)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
def self.extract(backtrace)
|
54
|
+
backtrace.map {|s| StackDeck::Frame::Ruby.parse(s) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def boundary?
|
58
|
+
filename == __FILE__ && function == 'boundary'
|
59
|
+
end
|
60
|
+
def to_s
|
61
|
+
"#{filename}:#{lineno}: in `#{function}'"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class JavaScript < Frame
|
66
|
+
def self.parse(str)
|
67
|
+
if str =~ /^(.*)@(.*?):(\d+|\?)$/
|
68
|
+
function = $1
|
69
|
+
filename = $2
|
70
|
+
lineno = $3.to_i
|
71
|
+
|
72
|
+
return if filename == '' && function =~ /^(apply|call)\(/
|
73
|
+
return if filename == '' && function == '' && lineno == 0
|
74
|
+
return if function =~ /^__hidden(_[A-Za-z0-9_]*)?\(/
|
75
|
+
filename = filename.squeeze('/')
|
76
|
+
|
77
|
+
function.sub!(/\(.*/, '')
|
78
|
+
|
79
|
+
new(function, filename, lineno)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class SQL < Frame
|
85
|
+
def self.from_char(query, position)
|
86
|
+
before = query[0, position.to_i]
|
87
|
+
lineno = 1 + before.size - before.gsub(/\n/, '').size
|
88
|
+
self.new(query, lineno)
|
89
|
+
end
|
90
|
+
|
91
|
+
def initialize(query, lineno=nil, clue=nil)
|
92
|
+
@query = query
|
93
|
+
super(nil, nil, lineno, clue)
|
94
|
+
end
|
95
|
+
def context
|
96
|
+
@context ||= Context.new(@query.split(/\n/), lineno) if @query
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
require 'stackdeck'
|
3
|
+
|
4
|
+
module StackDeck
|
5
|
+
class Context
|
6
|
+
class PgProc < Context
|
7
|
+
def initialize(conn, function, lineno)
|
8
|
+
# This will obviously fail on an overloaded function, returning
|
9
|
+
# the source of one arbitrarily-chosen variant.
|
10
|
+
src = conn.query('SELECT prosrc FROM pg_proc WHERE proname = ? ORDER BY pronargs DESC LIMIT 1', function)
|
11
|
+
src = src.first until String === src
|
12
|
+
|
13
|
+
lines = src.split(/\r?\n/)
|
14
|
+
|
15
|
+
# Apparently, if the first line of the function is empty (doesn't
|
16
|
+
# even contain any whitespace), PG doesn't count it when numbering
|
17
|
+
# lines. So we join in, by pretending it isn't there.
|
18
|
+
lines.shift if lines.first.empty?
|
19
|
+
|
20
|
+
super lines, lineno
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Frame
|
26
|
+
module Postgres
|
27
|
+
class Function < Frame
|
28
|
+
def initialize(conn, language, function, lineno, clue=nil)
|
29
|
+
@db_connection = conn
|
30
|
+
@language = language
|
31
|
+
super(function, nil, lineno, clue)
|
32
|
+
end
|
33
|
+
def context
|
34
|
+
@context ||= Context::PgProc.new(@db_connection, function, lineno) if @db_connection
|
35
|
+
end
|
36
|
+
def language
|
37
|
+
@language.gsub(/ function$/, '')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.extract(ex)
|
42
|
+
postgres_stack = []
|
43
|
+
if ex.internal_query
|
44
|
+
postgres_stack << Frame::SQL.from_char(ex.internal_query, ex.internal_position)
|
45
|
+
end
|
46
|
+
if ex.context
|
47
|
+
postgres_stack.concat ex.context.split(/\n/).map {|s| parse(s) }
|
48
|
+
end
|
49
|
+
if ex.query
|
50
|
+
postgres_stack << Frame::SQL.from_char(ex.query, ex.query_position)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.parse(str, conn=nil)
|
55
|
+
if str =~ /([^"]+) "(.*)"(?: line (\d+))?(?: (at [^"]+))?$/
|
56
|
+
case $1
|
57
|
+
when 'SQL statement'
|
58
|
+
Frame::SQL.new($2)
|
59
|
+
else
|
60
|
+
f = $1.empty? ? nil : $1
|
61
|
+
self::Function.new(conn, f, $2, $3.to_i, $4)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stackdeck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Draper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-10 00:00:00 +10:30
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Manages stack traces across language boundaries.
|
17
|
+
email: matthew@trebex.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- lib/stackdeck.rb
|
33
|
+
- lib/stackdeck/context.rb
|
34
|
+
- lib/stackdeck/exception.rb
|
35
|
+
- lib/stackdeck/file_reader.rb
|
36
|
+
- lib/stackdeck/frame.rb
|
37
|
+
- lib/stackdeck/postgres.rb
|
38
|
+
- test/helper.rb
|
39
|
+
- test/test_stackdeck.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/matthewd/stackdeck
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Manages stack traces across language boundaries
|
68
|
+
test_files:
|
69
|
+
- test/helper.rb
|
70
|
+
- test/test_stackdeck.rb
|