better_errors 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +26 -8
- data/better_errors.gemspec +7 -5
- data/lib/better_errors/code_formatter.rb +60 -0
- data/lib/better_errors/core_ext/exception.rb +14 -13
- data/lib/better_errors/error_page.rb +36 -47
- data/lib/better_errors/middleware.rb +41 -2
- data/lib/better_errors/rails.rb +5 -4
- data/lib/better_errors/repl/basic.rb +20 -0
- data/lib/better_errors/repl/pry.rb +67 -0
- data/lib/better_errors/repl.rb +27 -0
- data/lib/better_errors/{error_frame.rb → stack_frame.rb} +30 -8
- data/lib/better_errors/templates/main.erb +480 -0
- data/lib/better_errors/templates/variable_info.erb +13 -0
- data/lib/better_errors/version.rb +1 -1
- data/lib/better_errors.rb +4 -2
- data/spec/better_errors/code_formatter_spec.rb +51 -0
- data/spec/better_errors/error_page_spec.rb +31 -16
- data/spec/better_errors/middleware_spec.rb +8 -0
- data/spec/better_errors/repl/basic_spec.rb +32 -0
- data/spec/better_errors/{error_frame_spec.rb → stack_frame_spec.rb} +8 -8
- metadata +23 -13
- data/lib/better_errors/error_page.erb +0 -234
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
module BetterErrors
|
|
4
|
-
describe
|
|
4
|
+
describe StackFrame do
|
|
5
5
|
context "#application?" do
|
|
6
6
|
it "should be true for application filenames" do
|
|
7
7
|
BetterErrors.stub!(:application_root).and_return("/abc/xyz")
|
|
8
|
-
frame =
|
|
8
|
+
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
|
9
9
|
|
|
10
10
|
frame.application?.should be_true
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "should be false for everything else" do
|
|
14
14
|
BetterErrors.stub!(:application_root).and_return("/abc/xyz")
|
|
15
|
-
frame =
|
|
15
|
+
frame = StackFrame.new("/abc/nope", 123, "foo")
|
|
16
16
|
|
|
17
17
|
frame.application?.should be_false
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "should not care if no application_root is set" do
|
|
21
|
-
frame =
|
|
21
|
+
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
|
22
22
|
|
|
23
23
|
frame.application?.should be_false
|
|
24
24
|
end
|
|
@@ -27,14 +27,14 @@ module BetterErrors
|
|
|
27
27
|
context "#gem?" do
|
|
28
28
|
it "should be true for gem filenames" do
|
|
29
29
|
Gem.stub!(:path).and_return(["/abc/xyz"])
|
|
30
|
-
frame =
|
|
30
|
+
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
|
31
31
|
|
|
32
32
|
frame.gem?.should be_true
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "should be false for everything else" do
|
|
36
36
|
Gem.stub!(:path).and_return(["/abc/xyz"])
|
|
37
|
-
frame =
|
|
37
|
+
frame = StackFrame.new("/abc/nope", 123, "foo")
|
|
38
38
|
|
|
39
39
|
frame.gem?.should be_false
|
|
40
40
|
end
|
|
@@ -43,7 +43,7 @@ module BetterErrors
|
|
|
43
43
|
context "#application_path" do
|
|
44
44
|
it "should chop off the application root" do
|
|
45
45
|
BetterErrors.stub!(:application_root).and_return("/abc/xyz")
|
|
46
|
-
frame =
|
|
46
|
+
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
|
47
47
|
|
|
48
48
|
frame.application_path.should == "app/controllers/crap_controller.rb"
|
|
49
49
|
end
|
|
@@ -52,7 +52,7 @@ module BetterErrors
|
|
|
52
52
|
context "#gem_path" do
|
|
53
53
|
it "should chop of the gem path and stick (gem) there" do
|
|
54
54
|
Gem.stub!(:path).and_return(["/abc/xyz"])
|
|
55
|
-
frame =
|
|
55
|
+
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
|
56
56
|
|
|
57
57
|
frame.gem_path.should == "(gem) whatever-1.2.3/lib/whatever.rb"
|
|
58
58
|
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.1.0
|
|
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-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -34,7 +34,7 @@ dependencies:
|
|
|
34
34
|
requirements:
|
|
35
35
|
- - ! '>='
|
|
36
36
|
- !ruby/object:Gem::Version
|
|
37
|
-
version:
|
|
37
|
+
version: 2.7.0
|
|
38
38
|
type: :runtime
|
|
39
39
|
prerelease: false
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -42,7 +42,7 @@ dependencies:
|
|
|
42
42
|
requirements:
|
|
43
43
|
- - ! '>='
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version:
|
|
45
|
+
version: 2.7.0
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: coderay
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -50,7 +50,7 @@ dependencies:
|
|
|
50
50
|
requirements:
|
|
51
51
|
- - ! '>='
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
53
|
+
version: 1.0.0
|
|
54
54
|
type: :runtime
|
|
55
55
|
prerelease: false
|
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -58,8 +58,10 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - ! '>='
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
62
|
-
description:
|
|
61
|
+
version: 1.0.0
|
|
62
|
+
description: Provides a better error page for Rails and other Rack apps. Includes
|
|
63
|
+
source code inspection, a live REPL and local/instance variable inspection for all
|
|
64
|
+
stack frames.
|
|
63
65
|
email:
|
|
64
66
|
- charlie@charliesomerville.com
|
|
65
67
|
executables: []
|
|
@@ -73,16 +75,23 @@ files:
|
|
|
73
75
|
- Rakefile
|
|
74
76
|
- better_errors.gemspec
|
|
75
77
|
- lib/better_errors.rb
|
|
78
|
+
- lib/better_errors/code_formatter.rb
|
|
76
79
|
- lib/better_errors/core_ext/exception.rb
|
|
77
|
-
- lib/better_errors/error_frame.rb
|
|
78
|
-
- lib/better_errors/error_page.erb
|
|
79
80
|
- lib/better_errors/error_page.rb
|
|
80
81
|
- lib/better_errors/middleware.rb
|
|
81
82
|
- lib/better_errors/rails.rb
|
|
83
|
+
- lib/better_errors/repl.rb
|
|
84
|
+
- lib/better_errors/repl/basic.rb
|
|
85
|
+
- lib/better_errors/repl/pry.rb
|
|
86
|
+
- lib/better_errors/stack_frame.rb
|
|
87
|
+
- lib/better_errors/templates/main.erb
|
|
88
|
+
- lib/better_errors/templates/variable_info.erb
|
|
82
89
|
- lib/better_errors/version.rb
|
|
83
|
-
- spec/better_errors/
|
|
90
|
+
- spec/better_errors/code_formatter_spec.rb
|
|
84
91
|
- spec/better_errors/error_page_spec.rb
|
|
85
92
|
- spec/better_errors/middleware_spec.rb
|
|
93
|
+
- spec/better_errors/repl/basic_spec.rb
|
|
94
|
+
- spec/better_errors/stack_frame_spec.rb
|
|
86
95
|
- spec/better_errors/support/my_source.rb
|
|
87
96
|
- spec/spec_helper.rb
|
|
88
97
|
homepage: https://github.com/charliesome/better_errors
|
|
@@ -109,11 +118,12 @@ rubyforge_project:
|
|
|
109
118
|
rubygems_version: 1.8.24
|
|
110
119
|
signing_key:
|
|
111
120
|
specification_version: 3
|
|
112
|
-
summary: Better
|
|
121
|
+
summary: Better error page for Rails and other Rack apps
|
|
113
122
|
test_files:
|
|
114
|
-
- spec/better_errors/
|
|
123
|
+
- spec/better_errors/code_formatter_spec.rb
|
|
115
124
|
- spec/better_errors/error_page_spec.rb
|
|
116
125
|
- spec/better_errors/middleware_spec.rb
|
|
126
|
+
- spec/better_errors/repl/basic_spec.rb
|
|
127
|
+
- spec/better_errors/stack_frame_spec.rb
|
|
117
128
|
- spec/better_errors/support/my_source.rb
|
|
118
129
|
- spec/spec_helper.rb
|
|
119
|
-
has_rdoc:
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title><%= exception.class %> at <%= request_path %></title>
|
|
5
|
-
<style>
|
|
6
|
-
* {
|
|
7
|
-
margin:0;
|
|
8
|
-
padding:0;
|
|
9
|
-
}
|
|
10
|
-
body {
|
|
11
|
-
font-family:Verdana, sans-serif;
|
|
12
|
-
margin:0;
|
|
13
|
-
font-size:13px;
|
|
14
|
-
}
|
|
15
|
-
header {
|
|
16
|
-
padding:32px 32px;
|
|
17
|
-
border-bottom:1px solid #ea6756;
|
|
18
|
-
background-color: #ffe5e7;
|
|
19
|
-
background-image: -webkit-gradient(linear, left top, left bottom, from(#ffe5e7), to(#ffb2b8)); /* Safari 4+, Chrome */
|
|
20
|
-
background-image: -webkit-linear-gradient(top, #ffe5e7, #ffb2b8); /* Chrome 10+, Safari 5.1+, iOS 5+ */
|
|
21
|
-
background-image: -moz-linear-gradient(top, #ffe5e7, #ffb2b8); /* Firefox 3.6-15 */
|
|
22
|
-
background-image: -o-linear-gradient(top, #ffe5e7, #ffb2b8); /* Opera 11.10-12.00 */
|
|
23
|
-
background-image: linear-gradient(to bottom, #ffe5e7, #ffb2b8); /* Firefox 16+, IE10, Opera 12.50+ */
|
|
24
|
-
}
|
|
25
|
-
h2 {
|
|
26
|
-
font-weight:normal;
|
|
27
|
-
margin:0;
|
|
28
|
-
margin-bottom:16px;
|
|
29
|
-
}
|
|
30
|
-
h2 span {
|
|
31
|
-
color:#666666;
|
|
32
|
-
}
|
|
33
|
-
header table {
|
|
34
|
-
border-collapse:collapse;
|
|
35
|
-
}
|
|
36
|
-
header table th {
|
|
37
|
-
text-align:right;
|
|
38
|
-
font-weight:bold;
|
|
39
|
-
padding-right:12px;
|
|
40
|
-
}
|
|
41
|
-
header table th, header table td {
|
|
42
|
-
padding:4px 6px;
|
|
43
|
-
}
|
|
44
|
-
.frames {
|
|
45
|
-
width:50%;
|
|
46
|
-
float:left;
|
|
47
|
-
}
|
|
48
|
-
.frames li {
|
|
49
|
-
list-style:none;
|
|
50
|
-
display:block;
|
|
51
|
-
padding:12px;
|
|
52
|
-
overflow:hidden;
|
|
53
|
-
cursor:pointer;
|
|
54
|
-
background-color: #f4f7ff;
|
|
55
|
-
background-image: -webkit-gradient(linear, left top, left bottom, from(#f4f7ff), to(#e4ebfe)); /* Safari 4+, Chrome */
|
|
56
|
-
background-image: -webkit-linear-gradient(top, #f4f7ff, #e4ebfe); /* Chrome 10+, Safari 5.1+, iOS 5+ */
|
|
57
|
-
background-image: -moz-linear-gradient(top, #f4f7ff, #e4ebfe); /* Firefox 3.6-15 */
|
|
58
|
-
background-image: -o-linear-gradient(top, #f4f7ff, #e4ebfe); /* Opera 11.10-12.00 */
|
|
59
|
-
background-image: linear-gradient(to bottom, #f4f7ff, #e4ebfe); /* Firefox 16+, IE10, Opera 12.50+ */
|
|
60
|
-
border-bottom:1px solid #cccccc;
|
|
61
|
-
}
|
|
62
|
-
.frames li:hover, .frames li.selected {
|
|
63
|
-
background-color: #e4ebfe;
|
|
64
|
-
background-image: -webkit-gradient(linear, left top, left bottom, from(#e4ebfe), to(#c2d3fe)); /* Safari 4+, Chrome */
|
|
65
|
-
background-image: -webkit-linear-gradient(top, #e4ebfe, #c2d3fe); /* Chrome 10+, Safari 5.1+, iOS 5+ */
|
|
66
|
-
background-image: -moz-linear-gradient(top, #e4ebfe, #c2d3fe); /* Firefox 3.6-15 */
|
|
67
|
-
background-image: -o-linear-gradient(top, #e4ebfe, #c2d3fe); /* Opera 11.10-12.00 */
|
|
68
|
-
background-image: linear-gradient(to bottom, #e4ebfe, #c2d3fe); /* Firefox 16+, IE10, Opera 12.50+ */
|
|
69
|
-
}
|
|
70
|
-
.frames .name, .frame_info h2.name {
|
|
71
|
-
font-family:Monaco, Incosolata, Consolas, monospace;
|
|
72
|
-
font-size:14px;
|
|
73
|
-
margin-bottom:4px;
|
|
74
|
-
}
|
|
75
|
-
.location {
|
|
76
|
-
color:#888888;
|
|
77
|
-
}
|
|
78
|
-
.location .filename, .location .line {
|
|
79
|
-
color:#333333;
|
|
80
|
-
}
|
|
81
|
-
.frame_info {
|
|
82
|
-
background-color:#efefef;
|
|
83
|
-
border-bottom:1px solid #cccccc;
|
|
84
|
-
float:left;
|
|
85
|
-
width:50%;
|
|
86
|
-
}
|
|
87
|
-
.frame_info > * {
|
|
88
|
-
margin:16px;
|
|
89
|
-
}
|
|
90
|
-
.frame_info h2 {
|
|
91
|
-
font-family:Monaco, Incosolata, Consolas, monospace;
|
|
92
|
-
}
|
|
93
|
-
.frame_info .code {
|
|
94
|
-
font-family:Monaco, Incosolata, Consolas, monospace;
|
|
95
|
-
background-color:#ffffff;
|
|
96
|
-
border:1px solid #cccccc;
|
|
97
|
-
border-collapse:collapse;
|
|
98
|
-
overflow:auto;
|
|
99
|
-
}
|
|
100
|
-
.frame_info .code pre:nth-child(2n+1) {
|
|
101
|
-
background-color:#f9f9f9;
|
|
102
|
-
}
|
|
103
|
-
.frame_info .code pre:nth-child(2n) {
|
|
104
|
-
background-color:#f3f3f3;
|
|
105
|
-
}
|
|
106
|
-
.frame_info .code pre.highlight {
|
|
107
|
-
background-color:#ffeaaa;
|
|
108
|
-
}
|
|
109
|
-
.frame_info .code .line {
|
|
110
|
-
text-align:right;
|
|
111
|
-
padding-right:12px;
|
|
112
|
-
padding-left:0px;
|
|
113
|
-
}
|
|
114
|
-
code {
|
|
115
|
-
background-color:#f0f0f0;
|
|
116
|
-
padding:2px 4px;
|
|
117
|
-
border:1px solid #d0d0d0;
|
|
118
|
-
}
|
|
119
|
-
h3 {
|
|
120
|
-
font-weight:normal;
|
|
121
|
-
border-top:1px solid #cccccc;
|
|
122
|
-
padding-top:16px;
|
|
123
|
-
}
|
|
124
|
-
.var_table {
|
|
125
|
-
border-collapse:collapse;
|
|
126
|
-
}
|
|
127
|
-
.var_table td {
|
|
128
|
-
padding:8px;
|
|
129
|
-
}
|
|
130
|
-
.var_table td.name {
|
|
131
|
-
font-style:italic;
|
|
132
|
-
}
|
|
133
|
-
.var_table tr {
|
|
134
|
-
border-bottom:1px solid #cccccc;
|
|
135
|
-
}
|
|
136
|
-
</style>
|
|
137
|
-
</head>
|
|
138
|
-
<body>
|
|
139
|
-
<header>
|
|
140
|
-
<h2><%= exception.class %> <span>at <%= request_path %></span></h2>
|
|
141
|
-
<table>
|
|
142
|
-
<tr>
|
|
143
|
-
<th>Message</th>
|
|
144
|
-
<td><%= exception.message %></td>
|
|
145
|
-
</tr>
|
|
146
|
-
<% if backtrace_frames.any? %>
|
|
147
|
-
<tr>
|
|
148
|
-
<th>File</th>
|
|
149
|
-
<td><%= backtrace_frames.first.filename %></td>
|
|
150
|
-
</tr>
|
|
151
|
-
<tr>
|
|
152
|
-
<th>Line</th>
|
|
153
|
-
<td><%= backtrace_frames.first.line %></td>
|
|
154
|
-
</tr>
|
|
155
|
-
<% end %>
|
|
156
|
-
</table>
|
|
157
|
-
</header>
|
|
158
|
-
<section class="backtrace">
|
|
159
|
-
<ul class="frames">
|
|
160
|
-
<% backtrace_frames.each_with_index do |frame, index| %>
|
|
161
|
-
<li
|
|
162
|
-
data-context="<%= frame.context %>"
|
|
163
|
-
data-full-filename="<%= frame.filename %>"
|
|
164
|
-
data-filename="<%= frame.pretty_path %>"
|
|
165
|
-
data-line="<%= frame.line %>"
|
|
166
|
-
data-name="<%= frame.name %>"
|
|
167
|
-
data-index="<%= index %>"
|
|
168
|
-
>
|
|
169
|
-
<div class="name"><%= frame.name %></div>
|
|
170
|
-
<div class="location"><span class="filename"><%= frame.pretty_path %></span>, line <span class="line"><%= frame.line %></span></div>
|
|
171
|
-
</li>
|
|
172
|
-
<% end %>
|
|
173
|
-
</ul>
|
|
174
|
-
<% backtrace_frames.each_with_index do |frame, index| %>
|
|
175
|
-
<div class="frame_info" id="frame_info_<%= index %>" style="display:none;">
|
|
176
|
-
<h2 class="name"><%= frame.name %></h2>
|
|
177
|
-
<div class="location"><span class="filename"><%= frame.pretty_path %></span>, line <span class="line"><%= frame.line %></span></div>
|
|
178
|
-
<%== highlighted_code_block frame %>
|
|
179
|
-
|
|
180
|
-
<h3>Local Variables</h3>
|
|
181
|
-
<table class="var_table">
|
|
182
|
-
<% frame.local_variables.each do |name, value| %>
|
|
183
|
-
<tr><td class="name"><%= name %></td><td><pre><%= value.inspect %></pre></td></tr>
|
|
184
|
-
<% end %>
|
|
185
|
-
</table>
|
|
186
|
-
|
|
187
|
-
<h3>Instance Variables</h3>
|
|
188
|
-
<table class="var_table">
|
|
189
|
-
<% frame.instance_variables.each do |name, value| %>
|
|
190
|
-
<tr><td class="name"><%= name %></td><td><pre><%= value.inspect %></pre></td></tr>
|
|
191
|
-
<% end %>
|
|
192
|
-
</table>
|
|
193
|
-
</div>
|
|
194
|
-
<% end %>
|
|
195
|
-
<div style="clear:both"></div>
|
|
196
|
-
</section>
|
|
197
|
-
</body>
|
|
198
|
-
<script>
|
|
199
|
-
(function() {
|
|
200
|
-
var previous = null;
|
|
201
|
-
var previousFrameInfo = null;
|
|
202
|
-
var frames = document.querySelectorAll("ul.frames li");
|
|
203
|
-
|
|
204
|
-
var header = document.querySelector("header");
|
|
205
|
-
var headerHeight = header.offsetHeight;
|
|
206
|
-
|
|
207
|
-
function selectFrameInfo(index) {
|
|
208
|
-
var el = document.getElementById("frame_info_" + index);
|
|
209
|
-
|
|
210
|
-
if(previousFrameInfo) {
|
|
211
|
-
previousFrameInfo.style.display = "none";
|
|
212
|
-
}
|
|
213
|
-
previousFrameInfo = el;
|
|
214
|
-
previousFrameInfo.style.display = "block";
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
for(var i = 0; i < frames.length; i++) {
|
|
218
|
-
(function(el) {
|
|
219
|
-
el.onclick = function() {
|
|
220
|
-
if(previous) {
|
|
221
|
-
previous.className = "";
|
|
222
|
-
}
|
|
223
|
-
el.className = "selected";
|
|
224
|
-
previous = el;
|
|
225
|
-
|
|
226
|
-
selectFrameInfo(el.attributes["data-index"].value);
|
|
227
|
-
};
|
|
228
|
-
})(frames[i]);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
document.querySelector(".frames li:first-child").click();
|
|
232
|
-
})();
|
|
233
|
-
</script>
|
|
234
|
-
</html>
|