better_errors 0.1.0 → 0.1.1

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.

@@ -50,6 +50,14 @@ module BetterErrors
50
50
  end
51
51
 
52
52
  private
53
+ def exception_message
54
+ if exception.is_a?(SyntaxError) && exception.message =~ /\A.*:\d*: (.*)$/
55
+ $1
56
+ else
57
+ exception.message
58
+ end
59
+ end
60
+
53
61
  def real_exception(exception)
54
62
  if exception.respond_to? :original_exception
55
63
  exception.original_exception
@@ -1,16 +1,18 @@
1
1
  module BetterErrors
2
2
  module REPL
3
3
  PROVIDERS = [
4
- { impl: "better_errors/repl/pry",
5
- const: :Pry },
6
4
  { impl: "better_errors/repl/basic",
7
5
  const: :Basic },
8
6
  ]
9
-
7
+
10
8
  def self.provider
11
9
  @provider ||= const_get detect[:const]
12
10
  end
13
11
 
12
+ def self.provider=(prov)
13
+ @provider = prov
14
+ end
15
+
14
16
  def self.detect
15
17
  PROVIDERS.find do |prov|
16
18
  test_provider prov
@@ -2,7 +2,7 @@ module BetterErrors
2
2
  class StackFrame
3
3
  def self.from_exception(exception)
4
4
  idx_offset = 0
5
- exception.backtrace.each_with_index.map { |frame, idx|
5
+ list = exception.backtrace.each_with_index.map do |frame, idx|
6
6
  frame_binding = exception.__better_errors_bindings_stack[idx - idx_offset]
7
7
  md = /\A(?<file>.*):(?<line>\d*):in `(?<name>.*)'\z/.match(frame)
8
8
 
@@ -13,7 +13,13 @@ module BetterErrors
13
13
  end
14
14
 
15
15
  StackFrame.new(md[:file], md[:line].to_i, md[:name], frame_binding)
16
- }.compact
16
+ end
17
+
18
+ if exception.is_a?(SyntaxError) && exception.to_s =~ /\A(.*):(\d*):/
19
+ list.unshift StackFrame.new($1, $2.to_i, "")
20
+ end
21
+
22
+ list
17
23
  end
18
24
 
19
25
  attr_reader :filename, :line, :name, :frame_binding
@@ -204,7 +204,7 @@
204
204
  <table>
205
205
  <tr>
206
206
  <th>Message</th>
207
- <td><%= exception.message %></td>
207
+ <td><%= exception_message %></td>
208
208
  </tr>
209
209
  <% if backtrace_frames.any? %>
210
210
  <tr>
@@ -245,15 +245,17 @@
245
245
  <%== highlighted_code_block frame %>
246
246
 
247
247
  <% if BetterErrors.binding_of_caller_available? %>
248
- <div class="repl">
249
- <h3>REPL</h3>
250
- <div class="console">
251
- <pre></pre>
252
- <div class="prompt"><span>&gt;&gt;</span> <input/></div>
248
+ <% if frame.frame_binding %>
249
+ <div class="repl">
250
+ <h3>REPL</h3>
251
+ <div class="console">
252
+ <pre></pre>
253
+ <div class="prompt"><span>&gt;&gt;</span> <input/></div>
254
+ </div>
253
255
  </div>
254
- </div>
255
-
256
- <div class="variable_info"></div>
256
+
257
+ <div class="variable_info"></div>
258
+ <% end %>
257
259
  <% else %>
258
260
  <h3>Advanced features unavailable</h3>
259
261
  <p class="error">
@@ -1,3 +1,3 @@
1
1
  module BetterErrors
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -57,5 +57,14 @@ module BetterErrors
57
57
  frame.gem_path.should == "(gem) whatever-1.2.3/lib/whatever.rb"
58
58
  end
59
59
  end
60
+
61
+ it "should special case SyntaxErrors" do
62
+ syntax_error = SyntaxError.new "my_file.rb:123: you wrote bad ruby!"
63
+ syntax_error.stub!(:backtrace).and_return([])
64
+ frames = StackFrame.from_exception(syntax_error)
65
+ frames.count.should == 1
66
+ frames.first.filename.should == "my_file.rb"
67
+ frames.first.line.should == 123
68
+ end
60
69
  end
61
70
  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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: