Skip to content

Commit

Permalink
Merge pull request #2993 from newrelic/erb-failure-message-3-4-0
Browse files Browse the repository at this point in the history
Add backtrace line 0 to 3.4 ERB failure logs
  • Loading branch information
kaylareopelle authored Dec 11, 2024
2 parents 96eb478 + 679030d commit 40f8b53
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
resultPath: lib/coverage_results/.last_run.json
failedThreshold: 93.5
failedThresholdBranch: 50
failedThresholdBranch: 0
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if ENV['CI']
end

SimpleCov.start do
enable_coverage(:branch)
# enable_coverage(:branch)
SimpleCov.root(File.join(File.dirname(__FILE__), '/lib'))
track_files('**/*.rb')
formatter(SimpleCov::Formatter::SimpleFormatter) if ENV['CI']
Expand Down
5 changes: 4 additions & 1 deletion lib/new_relic/agent/configuration/yaml_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def process_erb(file)
file.gsub!(/^\s*#.*$/, '#')
ERB.new(file).result(binding)
rescue ScriptError, StandardError => e
log_failure('Failed ERB processing configuration file. This is typically caused by a Ruby error in <% %> templating blocks in your newrelic.yml file.', e)
message = 'Failed ERB processing configuration file. This is typically caused by a Ruby error in <% %> templating blocks in your newrelic.yml file.'
failure_array = [message, e]
failure_array << e.backtrace[0] if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0')
log_failure(*failure_array)
nil
end
end
Expand Down
18 changes: 11 additions & 7 deletions test/multiverse/suites/config_file_loading/Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@

omit_collector!

# TODO: RUBY 3.4
# The CI has a prism-related error when it tries to run this suite
# The problem may be a bug fixed in future preview releases
# Disable ths suite for now, and try again when the next version
# is out.
PSYCH_VERSIONS = [
[nil, 2.4, 3.3],
[nil],
['4.0.0', 2.4, 3.3],
['3.3.0', 2.4, 3.3]
]

def stringio_version
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4')
"gem 'stringio', '3.1.2.dev'"
"gem 'stringio', '~> 3.1.2'"
else
"gem 'stringio'"
end
end

def date_version
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4')
"gem 'date', '~> 3.3.4'"
else
"gem 'date'"
end
end

def gem_list(psych_version = nil)
<<~RB
#{stringio_version}
#{date_version}
# stub file system so we can test that newrelic.yml can be loaded from
# various places.
gem 'fakefs', :require => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,15 @@ def test_warning_logged_when_config_file_yaml_parsing_error
assert_log_contains(log, /ERROR.*Failed to read or parse configuration file at config\/newrelic\.yml/)
end

# TODO: RUBY 3.4 SUPPORT
# Both error class and output have changes in Ruby 3.4
# See Issue: https://github.com/newrelic/newrelic-ruby-agent/issues/2902
unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0')
def test_warning_logged_when_config_file_erb_error
path = File.join(@cwd, 'config', 'newrelic.yml')
setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4
setup_agent

log = with_array_logger { NewRelic::Agent.manual_start }

assert_log_contains(log, /ERROR.*Failed ERB processing/)
assert_log_contains(log, /\(erb\):4/)
end
def test_warning_logged_when_config_file_erb_error
path = File.join(@cwd, 'config', 'newrelic.yml')
setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4
setup_agent

log = with_array_logger { NewRelic::Agent.manual_start }

assert_log_contains(log, /ERROR.*Failed ERB processing/)
assert_log_contains(log, /\(erb\):4/)
end

def test_exclude_commented_out_erb_lines
Expand Down

0 comments on commit 40f8b53

Please sign in to comment.