Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/spoom/context/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ module Bundle
#: -> String?
def read_gemfile
read("Gemfile")
rescue Errno::ENOENT, Errno::EACCES
nil
end

# Read the contents of the Gemfile.lock in this context directory
#: -> String?
def read_gemfile_lock
read("Gemfile.lock")
rescue Errno::ENOENT, Errno::EACCES
nil
end

# Set the `contents` of the Gemfile in this context directory
Expand Down Expand Up @@ -45,9 +49,10 @@ def bundle_exec(command, version: nil, capture_err: true)

#: -> Hash[String, Bundler::LazySpecification]
def gemfile_lock_specs
return {} unless file?("Gemfile.lock")
lockfile = read_gemfile_lock
return {} unless lockfile

parser = Bundler::LockfileParser.new(read_gemfile_lock)
parser = Bundler::LockfileParser.new(lockfile)
parser.specs.to_h { |spec| [spec.name, spec] }
end

Expand Down
9 changes: 7 additions & 2 deletions lib/spoom/context/sorbet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ def srb_metrics(*arg, sorbet_bin: nil, capture_err: true)
sorbet_bin: sorbet_bin,
capture_err: capture_err,
)
return unless file?(metrics_file)

metrics_path = absolute_path_to(metrics_file)
metrics = Spoom::Sorbet::Metrics::MetricsFileParser.parse_file(metrics_path)

begin
metrics = Spoom::Sorbet::Metrics::MetricsFileParser.parse_file(metrics_path)
rescue Errno::ENOENT, Errno::EACCES
return
end

remove!(metrics_file)
metrics
end
Expand Down
10 changes: 8 additions & 2 deletions lib/spoom/file_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def visit_path(path)

return if excluded_path?(path)

if File.file?(path)
begin
stat = File.stat(path)
rescue Errno::ENOENT, Errno::EACCES
return
end

if stat.file?
visit_file(path)
elsif File.directory?(path)
elsif stat.directory?
visit_directory(path)
else # rubocop:disable Style/EmptyElse
# Ignore aliases, sockets, etc.
Expand Down
1 change: 1 addition & 0 deletions lib/spoom/sorbet/metrics/metrics_file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module MetricsFileParser
DEFAULT_PREFIX = "ruby_typer.unknown."

class << self
# Raises if `path` doesn't point to a valid file that we have access to (see `File.read` for details)
#: (String path, ?String prefix) -> Hash[String, Integer]
def parse_file(path, prefix = DEFAULT_PREFIX)
parse_string(File.read(path), prefix)
Expand Down
Loading