From 3000fc8e18539f881603581c36d4378960190828 Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Sat, 28 Sep 2024 11:17:33 +0200 Subject: [PATCH] Fix Pathname to String conversion error In Rails apps the app root path is a Pathname instance. We can't use it the same way as a String when using it in `.start_with?` when comparing backtrace lines for error causes in `Transaction#first_formatted_backtrace_line`. Fix this by casting the root_path always to a String in the Config initializer so we're always sure it's a String and can use it as such. --- ...-implicit-conversion-of-pathname-into-string-error.md | 6 ++++++ lib/appsignal/config.rb | 2 +- spec/lib/appsignal/config_spec.rb | 9 +++++++++ spec/lib/appsignal/integrations/railtie_spec.rb | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changesets/fix-no-implicit-conversion-of-pathname-into-string-error.md diff --git a/.changesets/fix-no-implicit-conversion-of-pathname-into-string-error.md b/.changesets/fix-no-implicit-conversion-of-pathname-into-string-error.md new file mode 100644 index 00000000..0e0492c1 --- /dev/null +++ b/.changesets/fix-no-implicit-conversion-of-pathname-into-string-error.md @@ -0,0 +1,6 @@ +--- +bump: patch +type: fix +--- + +Fix 'no implicit conversion of Pathname into String' error when parsing backtrace lines of error causes in Rails apps. diff --git a/lib/appsignal/config.rb b/lib/appsignal/config.rb index 42399cdd..ee85eb39 100644 --- a/lib/appsignal/config.rb +++ b/lib/appsignal/config.rb @@ -212,7 +212,7 @@ def initialize( root_path, env ) - @root_path = root_path + @root_path = root_path.to_s @config_file_error = false @config_file = config_file @valid = false diff --git a/spec/lib/appsignal/config_spec.rb b/spec/lib/appsignal/config_spec.rb index 40755bd0..e3106725 100644 --- a/spec/lib/appsignal/config_spec.rb +++ b/spec/lib/appsignal/config_spec.rb @@ -371,6 +371,15 @@ def on_load end end + context "when root path is Pathname instance" do + let(:config) { described_class.new(Pathname.new("/path"), "production") } + + it "converts it to a String" do + expect(config.root_path).to eq("/path") + expect(config.root_path).to be_instance_of(String) + end + end + context "without config file" do let(:config) { described_class.new(tmp_dir, "production") } diff --git a/spec/lib/appsignal/integrations/railtie_spec.rb b/spec/lib/appsignal/integrations/railtie_spec.rb index fdb58a9c..db0c14a4 100644 --- a/spec/lib/appsignal/integrations/railtie_spec.rb +++ b/spec/lib/appsignal/integrations/railtie_spec.rb @@ -71,7 +71,7 @@ def initialize_railtie(event) it "sets the Rails app path as root_path" do initialize_railtie(event) - expect(Appsignal.config.root_path).to eq(Pathname.new(rails_project_fixture_path)) + expect(Appsignal.config.root_path).to eq(rails_project_fixture_path) end it "loads the Rails app name in the initial config" do