pretty_backtrace 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3572b7c273aed0de085880965919d39ff5f695a9
4
+ data.tar.gz: 32482304d2e4fb3b662b0ea4b7831d156fe4f317
5
+ SHA512:
6
+ metadata.gz: 978793b5cabdf4f7272dfc058fef5a496c920dda00b5071bee94216bd85596da4080cac020bf3b615f1b02c9b3cc8cfc11f126601fd0d164dbd42ceb77aea3dc
7
+ data.tar.gz: d1a1c7c98bbe2c7a6d259ed3087ce1a97f7cca53d92e22f615e2cdcc6f18044e4d2a7e01f72f562a128684c6814e3f584a9d23633f5d1529ef134f8816b394f5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pretty_backtrace.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Koichi Sasada
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # PrettyBacktrace
2
+
3
+ Pretty your exception backtrace.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pretty_backtrace'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pretty_backtrace
20
+
21
+ ## Usage
22
+
23
+ Use like that:
24
+
25
+ ```ruby
26
+ require 'pretty_backtrace'
27
+ PrettyBacktrace.enable
28
+
29
+ def recursive n
30
+ str = "Hi #{n}!!" * 128
31
+ if n > 0
32
+ recursive n - 1
33
+ else
34
+ raise "bottom of recursive"
35
+ end
36
+ end
37
+
38
+ recursive 3
39
+ ```
40
+
41
+ and you can see prettier backtrace (you can see local variable names and values).
42
+
43
+ ```
44
+ test.rb:10:in `recursive' (n = 0, str = "Hi 0!!Hi 0!!Hi 0!!Hi...): bottom of recursive (RuntimeError)
45
+ from test.rb:8:in `recursive' (n = 1, str = "Hi 1!!Hi 1!!Hi 1!!Hi...)
46
+ from test.rb:8:in `recursive' (n = 2, str = "Hi 2!!Hi 2!!Hi 2!!Hi...)
47
+ from test.rb:8:in `recursive' (n = 3, str = "Hi 3!!Hi 3!!Hi 3!!Hi...)
48
+ from test.rb:14:in `<main>'
49
+ ```
50
+
51
+ You only need to require "pretty_backtrace/enable" to eliminate "PrettyBacktrace.enable call".
52
+
53
+ PrettyBacktrace::CONFIG can change behaviour. See source code files for details.
54
+
55
+ ## Contributing
56
+
57
+ There are no spec tests. I love to get your contributions!
58
+
59
+ 1. Fork it ( https://github.com/ko1/pretty_backtrace/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task 'run' do
4
+ ruby 'test.rb'
5
+ end
@@ -0,0 +1,89 @@
1
+ require "pretty_backtrace/version"
2
+ require 'debug_inspector'
3
+
4
+ module PrettyBacktrace
5
+ CONFIG = {
6
+ truncate_length: 20,
7
+ disabled_exception_classes: {},
8
+ }
9
+
10
+ EXCEPTION_MODIFIER_TRACE = TracePoint.new(:raise){|tp|
11
+ begin
12
+ e = tp.raised_exception
13
+
14
+ CONFIG[:disabled_exception_classes].each{|klass, _|
15
+ next if e.kind_of?(klass)
16
+ }
17
+
18
+ RubyVM::DebugInspector.open{|dc|
19
+ locs = dc.backtrace_locations
20
+ pretty_backtrace = locs.map.with_index{|loc, i|
21
+ next if i < 2
22
+
23
+ iseq = dc.frame_iseq(i)
24
+
25
+ if iseq
26
+ b = dc.frame_binding(i)
27
+ lvs = iseq_local_variables(iseq)
28
+ lvs_val = lvs.inject({}){|r, lv|
29
+ v = b.local_variable_get(lv).inspect
30
+ r[lv] = v; r
31
+ }
32
+ else
33
+ lvs_val = {}
34
+ end
35
+
36
+ modify_trace_line loc, lvs_val
37
+ }.compact
38
+ e.set_backtrace pretty_backtrace
39
+ }
40
+ rescue => e
41
+ puts e
42
+ puts e.backtrace
43
+ fail "PrettyBacktrace BUG"
44
+ end
45
+ }
46
+
47
+ def self.enable
48
+ if block_given?
49
+ EXCEPTION_MODIFIER_TRACE.enable{
50
+ yield
51
+ }
52
+ else
53
+ EXCEPTION_MODIFIER_TRACE.enable
54
+ end
55
+ end
56
+
57
+ def self.disable
58
+ if block_given?
59
+ EXCEPTION_MODIFIER_TRACE.disable{
60
+ yield
61
+ }
62
+ else
63
+ EXCEPTION_MODIFIER_TRACE.disable
64
+ end
65
+ end
66
+
67
+ def self.iseq_local_variables iseq
68
+ _,_,_,_,arg_info,name,path,a_path,_,type,lvs, * = iseq.to_a
69
+ lvs
70
+ end
71
+
72
+ #
73
+ # local_variables_values is a Hash object containing pairs of
74
+ # a local variable name and value of local variable.
75
+ #
76
+ def self.modify_trace_line backtrace_location, local_variables_values
77
+ trace_line = backtrace_location.to_s
78
+
79
+ unless local_variables_values.empty?
80
+ additional = local_variables_values.map{|lv, v|
81
+ v = v[0..CONFIG[:truncate_length]] + '...' if v.length > CONFIG[:truncate_length]
82
+ "#{lv} = #{v.to_s}"
83
+ }.join(", ")
84
+ trace_line = "#{trace_line} (#{additional})"
85
+ end
86
+
87
+ trace_line
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ require "pretty_backtrace"
2
+ PrettyBacktrace.enable
3
+
@@ -0,0 +1,3 @@
1
+ module PrettyBacktrace
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pretty_backtrace/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pretty_backtrace"
8
+ spec.version = PrettyBacktrace::VERSION
9
+ spec.authors = ["Koichi Sasada"]
10
+ spec.email = ["ko1@atdot.net"]
11
+ spec.summary = %q{Pretty your exception backtrace.}
12
+ spec.description = %q{Pretty your exception backtrace.}
13
+ spec.homepage = "http://github.com/ko1/pretty_backtrace"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "debug_inspector", "~> 0.0.1"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
data/test.rb ADDED
@@ -0,0 +1,13 @@
1
+ $: << './lib'
2
+ require 'pretty_backtrace/enable'
3
+
4
+ def recursive n
5
+ str = "Hi #{n}!!" * 128
6
+ if n > 0
7
+ recursive n - 1
8
+ else
9
+ raise "bottom of recursive"
10
+ end
11
+ end
12
+
13
+ recursive 3
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pretty_backtrace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Koichi Sasada
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: debug_inspector
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Pretty your exception backtrace.
56
+ email:
57
+ - ko1@atdot.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/pretty_backtrace.rb
68
+ - lib/pretty_backtrace/enable.rb
69
+ - lib/pretty_backtrace/version.rb
70
+ - pretty_backtrace.gemspec
71
+ - test.rb
72
+ homepage: http://github.com/ko1/pretty_backtrace
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Pretty your exception backtrace.
96
+ test_files: []