Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue SyntaxError in AutoInstruments #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/scout_apm/auto_instrument/instruction_sequence.rb
Expand Up @@ -4,19 +4,19 @@
module ScoutApm
module AutoInstrument
module InstructionSequence
def load_iseq(path)
def self.load_iseq(path)
if Rails.controller_path?(path) & !Rails.ignore?(path)
begin
new_code = Rails.rewrite(path)
return self.compile(new_code, path, path)
rescue
warn "Failed to apply auto-instrumentation to #{path}: #{$!}"
return ::RubyVM::InstructionSequence.compile(new_code, path, path)
rescue StandardError, SyntaxError
warn "Failed to apply auto-instrumentation to #{path}: #{$!}" if ENV['SCOUT_LOG_LEVEL'].to_s.downcase == "debug"
end
elsif Rails.ignore?(path)
warn "AutoInstruments are ignored for path=#{path}."
warn "AutoInstruments are ignored for path=#{path}." if ENV['SCOUT_LOG_LEVEL'].to_s.downcase == "debug"
end

return self.compile_file(path)
return ::RubyVM::InstructionSequence.compile_file(path)
end
end

Expand Down
@@ -1,4 +1,4 @@
class TestController < ApplicationController
class AutoInstrumentTestController
def index
quests = policy_scope(Quest.open)
quests.each { _1.current_user = current_user }
Expand Down
4 changes: 3 additions & 1 deletion test/unit/auto_instrument_test.rb
Expand Up @@ -57,6 +57,8 @@ def test_hanging_method_rewrite
end

def test_anonymous_block_value
::ScoutApm::AutoInstrument::Rails.rewrite(source_path("anonymous_block_value"))
::ScoutApm::AutoInstrument::Rails.expects(:rewrite).once
::RubyVM::InstructionSequence.expects(:compile).once
::ScoutApm::AutoInstrument::InstructionSequence.load_iseq(source_path("app/controllers/anonymous_block_value_controller"))
end
end if defined? ScoutApm::AutoInstrument