better_errors 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of better_errors might be problematic. Click here for more details.
- data/README.md +1 -1
- data/lib/better_errors.rb +1 -1
- data/lib/better_errors/error_frame.rb +5 -1
- data/lib/better_errors/error_page.rb +7 -5
- data/lib/better_errors/middleware.rb +12 -0
- data/lib/better_errors/rails.rb +1 -0
- data/lib/better_errors/templates/main.erb +7 -2
- data/lib/better_errors/version.rb +1 -1
- data/spec/better_errors/error_page_spec.rb +30 -0
- data/spec/better_errors/middleware_spec.rb +8 -0
- metadata +2 -3
data/README.md
CHANGED
@@ -21,7 +21,7 @@ group :development do
|
|
21
21
|
end
|
22
22
|
```
|
23
23
|
|
24
|
-
If you would like to use Better Errors' **advanced features
|
24
|
+
If you would like to use Better Errors' **advanced features** (REPL, local/instance variable inspection, pretty stack frame names), you need to add the [`binding_of_caller`](https://github.com/banister/binding_of_caller) gem to your Gemfile:
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
gem "binding_of_caller"
|
data/lib/better_errors.rb
CHANGED
@@ -8,7 +8,7 @@ require "better_errors/error_frame"
|
|
8
8
|
require "better_errors/middleware"
|
9
9
|
|
10
10
|
class << BetterErrors
|
11
|
-
attr_accessor :application_root, :binding_of_caller_available
|
11
|
+
attr_accessor :application_root, :binding_of_caller_available, :logger
|
12
12
|
|
13
13
|
alias_method :binding_of_caller_available?, :binding_of_caller_available
|
14
14
|
end
|
@@ -76,11 +76,15 @@ module BetterErrors
|
|
76
76
|
Hash[frame_binding.eval("instance_variables").map { |x| [x, frame_binding.eval(x.to_s)] }]
|
77
77
|
end
|
78
78
|
|
79
|
+
def to_s
|
80
|
+
"#{pretty_path}:#{line}:in `#{name}'"
|
81
|
+
end
|
82
|
+
|
79
83
|
private
|
80
84
|
def set_pretty_method_name
|
81
85
|
name =~ /\A(block (\([^)]+\) )?in )?/
|
82
86
|
recv = frame_binding.eval("self")
|
83
|
-
method = frame_binding.eval("__method__")
|
87
|
+
return unless method = frame_binding.eval("__method__")
|
84
88
|
@name = if recv.is_a? Module
|
85
89
|
"#{$1}#{recv}.#{method}"
|
86
90
|
else
|
@@ -40,6 +40,10 @@ module BetterErrors
|
|
40
40
|
end
|
41
41
|
response.merge(highlighted_input: CodeRay.scan(opts["source"], :ruby).div(wrap: nil))
|
42
42
|
end
|
43
|
+
|
44
|
+
def backtrace_frames
|
45
|
+
@backtrace_frames ||= ErrorFrame.from_exception(exception)
|
46
|
+
end
|
43
47
|
|
44
48
|
private
|
45
49
|
def real_exception(exception)
|
@@ -53,10 +57,6 @@ module BetterErrors
|
|
53
57
|
def request_path
|
54
58
|
env["REQUEST_PATH"]
|
55
59
|
end
|
56
|
-
|
57
|
-
def backtrace_frames
|
58
|
-
@backtrace_frames ||= ErrorFrame.from_exception(exception)
|
59
|
-
end
|
60
60
|
|
61
61
|
def coderay_scanner_for_ext(ext)
|
62
62
|
case ext
|
@@ -64,6 +64,7 @@ module BetterErrors
|
|
64
64
|
when "html"; :html
|
65
65
|
when "erb"; :erb
|
66
66
|
when "haml"; :haml
|
67
|
+
else :text
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
@@ -75,6 +76,7 @@ module BetterErrors
|
|
75
76
|
lines = File.readlines(frame.filename)
|
76
77
|
min_line = [1, frame.line - lines_of_context].max - 1
|
77
78
|
max_line = [frame.line + lines_of_context, lines.count + 1].min - 1
|
79
|
+
raise Errno::EINVAL if min_line > lines.length
|
78
80
|
[min_line, max_line, lines[min_line..max_line].join]
|
79
81
|
end
|
80
82
|
|
@@ -95,7 +97,7 @@ module BetterErrors
|
|
95
97
|
end
|
96
98
|
html << "</div>"
|
97
99
|
end
|
98
|
-
rescue Errno::ENOENT
|
100
|
+
rescue Errno::ENOENT, Errno::EINVAL
|
99
101
|
"<p>Source unavailable</p>"
|
100
102
|
end
|
101
103
|
end
|
@@ -20,9 +20,21 @@ module BetterErrors
|
|
20
20
|
@app.call env
|
21
21
|
rescue Exception => ex
|
22
22
|
@error_page = @handler.new ex, env
|
23
|
+
log_exception
|
23
24
|
[500, { "Content-Type" => "text/html; charset=utf-8" }, [@error_page.render]]
|
24
25
|
end
|
25
26
|
|
27
|
+
def log_exception
|
28
|
+
return unless BetterErrors.logger
|
29
|
+
|
30
|
+
message = "\n#{@error_page.exception.class} - #{@error_page.exception.message}:\n"
|
31
|
+
@error_page.backtrace_frames.each do |frame|
|
32
|
+
message << " #{frame}\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
BetterErrors.logger.fatal message
|
36
|
+
end
|
37
|
+
|
26
38
|
def internal_call(env, opts)
|
27
39
|
if opts[:oid].to_i != @error_page.object_id
|
28
40
|
return [200, { "Content-Type" => "text/plain; charset=utf-8" }, [JSON.dump(error: "Session expired")]]
|
data/lib/better_errors/rails.rb
CHANGED
@@ -3,6 +3,7 @@ module BetterErrors
|
|
3
3
|
initializer "better_errors.configure_rails_initialization" do
|
4
4
|
unless Rails.env.production?
|
5
5
|
Rails.application.middleware.use BetterErrors::Middleware
|
6
|
+
BetterErrors.logger = Rails.logger
|
6
7
|
BetterErrors.application_root = Rails.root.to_s
|
7
8
|
end
|
8
9
|
end
|
@@ -352,8 +352,6 @@
|
|
352
352
|
})(i, frames[i], frameInfos[i]);
|
353
353
|
}
|
354
354
|
|
355
|
-
document.querySelector(".frames li:first-child").click();
|
356
|
-
|
357
355
|
var applicationFrames = document.getElementById("application_frames");
|
358
356
|
var allFrames = document.getElementById("all_frames");
|
359
357
|
|
@@ -380,6 +378,13 @@
|
|
380
378
|
};
|
381
379
|
|
382
380
|
applicationFrames.click();
|
381
|
+
|
382
|
+
for(var i = 0; i < frames.length; i++) {
|
383
|
+
if(frames[i].attributes["data-context"].value == "application") {
|
384
|
+
frames[i].click();
|
385
|
+
break;
|
386
|
+
}
|
387
|
+
}
|
383
388
|
})();
|
384
389
|
</script>
|
385
390
|
</html>
|
@@ -7,6 +7,16 @@ module BetterErrors
|
|
7
7
|
let(:error_page) { ErrorPage.new exception, { "REQUEST_PATH" => "/some/path" } }
|
8
8
|
|
9
9
|
let(:response) { error_page.render }
|
10
|
+
|
11
|
+
let(:empty_binding) {
|
12
|
+
local_a = :value_for_local_a
|
13
|
+
local_b = :value_for_local_b
|
14
|
+
|
15
|
+
@inst_c = :value_for_inst_c
|
16
|
+
@inst_d = :value_for_inst_d
|
17
|
+
|
18
|
+
binding
|
19
|
+
}
|
10
20
|
|
11
21
|
it "should include the error message" do
|
12
22
|
response.should include("you divided by zero you silly goose!")
|
@@ -42,6 +52,26 @@ module BetterErrors
|
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
55
|
+
context "variable inspection" do
|
56
|
+
let(:exception) { empty_binding.eval("raise") rescue $! }
|
57
|
+
|
58
|
+
it "should show local variables" do
|
59
|
+
html = error_page.do_variables("index" => 0)[:html]
|
60
|
+
html.should include("local_a")
|
61
|
+
html.should include(":value_for_local_a")
|
62
|
+
html.should include("local_b")
|
63
|
+
html.should include(":value_for_local_b")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should show instance variables" do
|
67
|
+
html = error_page.do_variables("index" => 0)[:html]
|
68
|
+
html.should include("inst_c")
|
69
|
+
html.should include(":value_for_inst_c")
|
70
|
+
html.should include("inst_d")
|
71
|
+
html.should include(":value_for_inst_d")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
45
75
|
it "should not die if the source file is not a real filename" do
|
46
76
|
exception.stub!(:backtrace).and_return([
|
47
77
|
"<internal:prelude>:10:in `spawn_rack_application'"
|
@@ -21,6 +21,14 @@ module BetterErrors
|
|
21
21
|
|
22
22
|
headers["Content-Type"].should == "text/html; charset=utf-8"
|
23
23
|
end
|
24
|
+
|
25
|
+
it "should log the exception" do
|
26
|
+
logger = Object.new
|
27
|
+
logger.should_receive :fatal
|
28
|
+
BetterErrors.stub!(:logger).and_return(logger)
|
29
|
+
|
30
|
+
app.call({})
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -119,4 +119,3 @@ test_files:
|
|
119
119
|
- spec/better_errors/middleware_spec.rb
|
120
120
|
- spec/better_errors/support/my_source.rb
|
121
121
|
- spec/spec_helper.rb
|
122
|
-
has_rdoc:
|