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 +4 -4
- data/lib/airbrake-ruby/code_hunk.rb +21 -18
- data/lib/airbrake-ruby/filters/gem_root_filter.rb +1 -1
- data/lib/airbrake-ruby/version.rb +1 -1
- data/spec/code_hunk_spec.rb +14 -2
- data/spec/notice_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aff45eea602c2f6f86609e6625146b33f91aa33
|
4
|
+
data.tar.gz: 51c9fb9f2f4e8d5df50832fbbfca92fda7e54239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
27
|
+
frame[:file] = file.sub(/\A#{gem_path}/, GEM_ROOT_LABEL)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/spec/code_hunk_spec.rb
CHANGED
@@ -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
|
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(
|
106
|
+
expect(Airbrake::FileCache).to receive(:[]).and_raise(Errno::EACCES)
|
95
107
|
end
|
96
108
|
|
97
109
|
it "logs error and returns nil" do
|
data/spec/notice_spec.rb
CHANGED
@@ -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":.+/
|
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.
|
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-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|