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

ProfdataCoverageFile: fix NoMethodError in source_file_pathname #539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jaysoffian
Copy link

Slather::Project::find_source_files previously could return nil, which would cause ProfdataCoverageFile::source_file_pathname to fail trying to call each on the nil value.

Update Slather::Project::find_source_files to return an empty list instead of nil. We then also need to update create_coverage_files to check whether source_file_pathname returns nil and if so, not include that coverage file.

Full stack trace:

.../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/profdata_coverage_file.rb:50:in `source_file_pathname': undefined method `each' for nil:NilClass (NoMethodError)

          project.find_source_files.each do |file|
                                   ^^^^^
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:185:in `block in create_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:180:in `map'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:180:in `create_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:153:in `create_coverage_files_for_binary'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:125:in `block in profdata_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:123:in `each'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:123:in `profdata_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:98:in `coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/coverage_service/sonarqube_xml_output.rb:18:in `post'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/command/coverage_command.rb:101:in `post'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/command/coverage_command.rb:61:in `execute'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/subcommand/execution.rb:18:in `execute'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/command.rb:140:in `run'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/bin/slather:17:in `<top (required)>'
	from .../.gem/ruby/3.2.1/bin/slather:25:in `load'
	from .../.gem/ruby/3.2.1/bin/slather:25:in `<main>'

Slather::Project::find_source_files previously could return nil, which
would cause ProfdataCoverageFile::source_file_pathname to fail trying
to call `each` on the nil value.

Update Slather::Project::find_source_files to return an empty list
instead of nil. We then also need to update `create_coverage_files` to
check whether source_file_pathname returns nil and if so, not include
that coverage file.

Full stack trace:

```
.../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/profdata_coverage_file.rb:50:in `source_file_pathname': undefined method `each' for nil:NilClass (NoMethodError)

          project.find_source_files.each do |file|
                                   ^^^^^
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:185:in `block in create_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:180:in `map'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:180:in `create_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:153:in `create_coverage_files_for_binary'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:125:in `block in profdata_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:123:in `each'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:123:in `profdata_coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/project.rb:98:in `coverage_files'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/coverage_service/sonarqube_xml_output.rb:18:in `post'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/command/coverage_command.rb:101:in `post'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/lib/slather/command/coverage_command.rb:61:in `execute'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/subcommand/execution.rb:18:in `execute'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
	from .../.gem/ruby/3.2.1/gems/clamp-1.3.2/lib/clamp/command.rb:140:in `run'
	from .../.gem/ruby/3.2.1/gems/slather-2.7.4/bin/slather:17:in `<top (required)>'
	from .../.gem/ruby/3.2.1/bin/slather:25:in `load'
	from .../.gem/ruby/3.2.1/bin/slather:25:in `<main>'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant