airbrake-ruby 2.5.0.rc.1 → 2.5.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5554bbef3980de04e9ba1028bb6378434e027bae
4
- data.tar.gz: 2b676212734c40e4952bdf00646052bec77fbd36
3
+ metadata.gz: 9aff45eea602c2f6f86609e6625146b33f91aa33
4
+ data.tar.gz: 51c9fb9f2f4e8d5df50832fbbfca92fda7e54239
5
5
  SHA512:
6
- metadata.gz: 2ebf2c15e4608233bbd88e05fa904008fdd401c65b549604e985d1199f9e44c9899df372a1224c6c65f4adb8d5be4211f7ff61642c0eadba6001208fc464e4cc
7
- data.tar.gz: 85cd37c40c76f1c94aa83382d90ac4b751a3c250a287ffbe36fa89b42f97868a2ef031010aa8ac11266bdc35379d737ee1ec1409f3057e0a8e087732f0c35bf5
6
+ metadata.gz: e7f2bf4d0415c18bb4385f612f7ca55ea2a8ee83259ee800dc058299e8f51ae1b51ec3c3467156a81547d2d1ad70d5717f1e6c01b53b6012f6a58a1cb141738c
7
+ data.tar.gz: a8f8a22d199ad6326812daca779c664c53b83c65cc772e370d5cb7ae0a1fb92a65df5b8a33ad8645880571be5ca9f85f44cb030747c4c8ec2ae7e999102d53eb
@@ -22,26 +22,11 @@ module Airbrake
22
22
  # @return [Hash{Integer=>String}, nil] lines of code around the base line
23
23
  def get(file, line)
24
24
  return unless File.exist?(file)
25
+ return unless line
25
26
 
26
- start_line = [line - NLINES, 1].max
27
- end_line = line + NLINES
28
- lines = {}
29
-
30
- begin
31
- get_from_cache(file).with_index(1) do |l, i|
32
- next if i < start_line
33
- break if i > end_line
34
-
35
- lines[i] = l[0...MAX_LINE_LEN].rstrip
36
- end
37
- rescue StandardError => ex
38
- @config.logger.error(
39
- "#{self.class.name}##{__method__}: can't read code hunk for " \
40
- "#{file}:#{line}: #{ex}\n#{ex.backtrace}"
41
- )
42
- end
43
-
27
+ lines = get_lines(file, [line - NLINES, 1].max, line + NLINES) || {}
44
28
  return { 1 => '' } if lines.empty?
29
+
45
30
  lines
46
31
  end
47
32
 
@@ -49,6 +34,24 @@ module Airbrake
49
34
 
50
35
  def get_from_cache(file)
51
36
  Airbrake::FileCache[file] ||= File.foreach(file)
37
+ rescue StandardError => ex
38
+ @config.logger.error(
39
+ "#{self.class.name}: can't read code hunk for #{file}: #{ex}"
40
+ )
41
+ nil
42
+ end
43
+
44
+ def get_lines(file, start_line, end_line)
45
+ return unless (cached_file = get_from_cache(file))
46
+
47
+ lines = {}
48
+ cached_file.with_index(1) do |l, i|
49
+ next if i < start_line
50
+ break if i > end_line
51
+
52
+ lines[i] = l[0...MAX_LINE_LEN].rstrip
53
+ end
54
+ lines
52
55
  end
53
56
  end
54
57
  end
@@ -24,7 +24,7 @@ module Airbrake
24
24
  # If the frame is unparseable, then 'file' is nil, thus nothing to
25
25
  # filter (all frame's data is in 'function' instead).
26
26
  next unless (file = frame[:file])
27
- file.sub!(/\A#{gem_path}/, GEM_ROOT_LABEL)
27
+ frame[:file] = file.sub(/\A#{gem_path}/, GEM_ROOT_LABEL)
28
28
  end
29
29
  end
30
30
  end
@@ -4,5 +4,5 @@
4
4
  module Airbrake
5
5
  ##
6
6
  # @return [String] the library version
7
- AIRBRAKE_RUBY_VERSION = '2.5.0.rc.1'.freeze
7
+ AIRBRAKE_RUBY_VERSION = '2.5.0.rc.2'.freeze
8
8
  end
@@ -3,8 +3,14 @@ require 'spec_helper'
3
3
  RSpec.describe Airbrake::CodeHunk do
4
4
  let(:config) { Airbrake::Config.new }
5
5
 
6
+ after do
7
+ %w[empty_file.rb code.rb banana.rb short_file.rb long_line.txt].each do |f|
8
+ Airbrake::FileCache[fixture_path(f)] = nil
9
+ end
10
+ end
11
+
6
12
  describe "#to_h" do
7
- context "when a file is empty" do
13
+ context "when file is empty" do
8
14
  subject do
9
15
  described_class.new(config).get(fixture_path('empty_file.rb'), 1)
10
16
  end
@@ -12,6 +18,12 @@ RSpec.describe Airbrake::CodeHunk do
12
18
  it { is_expected.to eq(1 => '') }
13
19
  end
14
20
 
21
+ context "when line is nil" do
22
+ subject { described_class.new(config).get(fixture_path('code.rb'), nil) }
23
+
24
+ it { is_expected.to be_nil }
25
+ end
26
+
15
27
  context "when a file doesn't exist" do
16
28
  subject { described_class.new(config).get(fixture_path('banana.rb'), 1) }
17
29
 
@@ -91,7 +103,7 @@ RSpec.describe Airbrake::CodeHunk do
91
103
 
92
104
  context "when an error occurrs while fetching code" do
93
105
  before do
94
- expect(File).to receive(:foreach).and_raise(Errno::EACCES)
106
+ expect(Airbrake::FileCache).to receive(:[]).and_raise(Errno::EACCES)
95
107
  end
96
108
 
97
109
  it "logs error and returns nil" do
@@ -207,7 +207,7 @@ RSpec.describe Airbrake::Notice do
207
207
 
208
208
  it "always contains environment/program_name" do
209
209
  expect(notice.to_json).
210
- to match(%r|"environment":{"program_name":.+/exe/rspec.*|)
210
+ to match(%r|"environment":{"program_name":.+/rspec.*|)
211
211
  end
212
212
  end
213
213
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0.rc.1
4
+ version: 2.5.0.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbrake Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-16 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec