Skip to content

Commit

Permalink
ErrorHighlight 0.5.1+ is always available since Ruby 3.2
Browse files Browse the repository at this point in the history
This commit removes conditions to see if ErrorHighligh 0.4.0 or higher version
is available since ErrorHighlight 0.5.1+ is always available since Ruby 3.2
that is required by the Rails current main branch.

- Ruby 3.2.0 Released
https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-released/

ErrorHighlight.spot(ex, backtrace_location: self)
> The following default gems are updated.
> error_highlight 0.5.1

Related to rails#48299 rails#53041
  • Loading branch information
yahonda committed Oct 4, 2024
1 parent 0df09dd commit 8a80f27
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
5 changes: 0 additions & 5 deletions actionpack/lib/action_dispatch/middleware/debug_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ def initialize(assigns)
paths = RESCUES_TEMPLATE_PATHS.dup
lookup_context = ActionView::LookupContext.new(paths)
super(lookup_context, assigns, nil)
@exception_wrapper = assigns[:exception_wrapper]
end

def compiled_method_container
self.class
end

def error_highlight_available?
@exception_wrapper.error_highlight_available?
end

def debug_params(params)
clean_params = params.clone
clean_params.delete("action")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ def source_extracts
end
end

def error_highlight_available?
# ErrorHighlight.spot with backtrace_location keyword is available since
# error_highlight 0.4.0
defined?(ErrorHighlight) && Gem::Version.new(ErrorHighlight::VERSION) >= Gem::Version.new("0.4.0")
end

def trace_to_show
if traces["Application Trace"].empty? && rescue_template != "routing_error"
"Full Trace"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
</tr>
</table>
</div>
<%- unless self.error_highlight_available? -%>
<p class="error_highlight_tip">Tip: You may want to add <code>gem "error_highlight", "&gt;= 0.4.0"</code> into your Gemfile, which will display the fine-grained error location.</p>
<%- end -%>
</div>
<% end %>
<% end %>
30 changes: 14 additions & 16 deletions actionpack/test/dispatch/exception_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,21 @@ def backtrace
assert_empty wrapper.source_extracts
end

if defined?(ErrorHighlight) && Gem::Version.new(ErrorHighlight::VERSION) >= Gem::Version.new("0.4.0")
test "#source_extracts works with error_highlight" do
lineno = __LINE__
begin
1.time
rescue NameError => exc
end

wrapper = ExceptionWrapper.new(nil, exc)

code = {}
File.foreach(__FILE__).to_a.drop(lineno - 1).take(6).each_with_index do |line, i|
code[lineno + i] = line
end
code[lineno + 2] = [" 1", ".time", "\n"]
assert_equal({ code: code, line_number: lineno + 2 }, wrapper.source_extracts.first)
test "#source_extracts works with error_highlight" do
lineno = __LINE__
begin
1.time
rescue NameError => exc
end

wrapper = ExceptionWrapper.new(nil, exc)

code = {}
File.foreach(__FILE__).to_a.drop(lineno - 1).take(6).each_with_index do |line, i|
code[lineno + i] = line
end
code[lineno + 2] = [" 1", ".time", "\n"]
assert_equal({ code: code, line_number: lineno + 2 }, wrapper.source_extracts.first)
end

test "#application_trace returns traces only from the application" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# frozen_string_literal: true

class Thread::Backtrace::Location # :nodoc:
if defined?(ErrorHighlight) && Gem::Version.new(ErrorHighlight::VERSION) >= Gem::Version.new("0.4.0")
def spot(ex)
ErrorHighlight.spot(ex, backtrace_location: self)
end
else
def spot(ex)
end
def spot(ex)
ErrorHighlight.spot(ex, backtrace_location: self)
end
end

0 comments on commit 8a80f27

Please sign in to comment.