From dd62149c1ff44915c601cce0e12043dc99e1ba0b Mon Sep 17 00:00:00 2001 From: Mario Caropreso Date: Wed, 16 Aug 2023 20:05:45 +0000 Subject: [PATCH] Addressed an issue where syntax errors generated inside an eval method cause an Internal Server Error due to a TypeError. In order to display the extraced source of a syntax error, we try to locate the node id for the backtrace location. The call to RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location is expecting a Thread::Backtrace::Location object, but we are passing a SourceMapLocation instead. This commit does two things: 1) it addresses the issue by making sure that we are always passing a Thread::Backtrace::Location instead 2) it allows the development view to show the extracted source fragment --- activesupport/lib/active_support/syntax_error_proxy.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/syntax_error_proxy.rb b/activesupport/lib/active_support/syntax_error_proxy.rb index 59d96d86813b..1e72a191b5a3 100644 --- a/activesupport/lib/active_support/syntax_error_proxy.rb +++ b/activesupport/lib/active_support/syntax_error_proxy.rb @@ -43,7 +43,8 @@ def backtrace_locations private def parse_message_for_trace - if __getobj__.to_s.start_with?("(eval") + # If RUBY_VERSION < 3.2, the path method is not available for SyntaxError + if __getobj__.try(:path).try(:start_with?,"(eval") || __getobj__.to_s.start_with?("(eval") # If the exception is coming from a call to eval, we need to keep # the path of the file in which eval was called to ensure we can # return the right source fragment to show the location of the