airbrake-ruby 1.3.0 → 1.3.1

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: dec071c8c6dc94827a5094f345a3e04f6e14d403
4
- data.tar.gz: f70b0927dcb8a948890cbe1f08f440dbffa832ea
3
+ metadata.gz: 14a1f47941cce7fb05a4606b830dad7d5021a808
4
+ data.tar.gz: 0c3bfcea4c50a6bfe983e15432bab8fe966ed327
5
5
  SHA512:
6
- metadata.gz: 23da1628abcb6f3db15af6988c346f102ebda373ee6ac30212981680cd76014de7c15cdf4e877e81ef7f6fbd7e7996f5c07501cf1472c4c9b9cb8f9e4be22a6d
7
- data.tar.gz: 5df62237f843c6521677c6e8f5ceb98547ef76d8931334fb6e611ca489dcb7337cb03044cad51d76375a4339ab426b750a5dd63e2d6addeda80c3f7cb1e0dc31
6
+ metadata.gz: 38deadf6ffea07e915398e08258766b86ab8b22a276622326c6ebd66b792da1f97beccaec485da2dc6edef81193b028926c539aac2966f2dffd436721fe6bac0
7
+ data.tar.gz: 6fa74b32ceb3907eaf1e0173c3d78fca7fefe3b0e94d9cad44b092abfafb7d0d57c2d81ed861d7c833e0b46689c3b81b1de1a74ac54203e80f6e9318b1526f8e
@@ -75,18 +75,18 @@ module Airbrake
75
75
  # notice's payload. Truncates notices, JSON representation of which is
76
76
  # bigger than {MAX_NOTICE_SIZE}.
77
77
  #
78
- # @return [Hash{String=>String}]
78
+ # @return [Hash{String=>String}, nil]
79
79
  def to_json
80
80
  loop do
81
81
  begin
82
82
  json = payload.to_json
83
83
  rescue *JSON_EXCEPTIONS => ex
84
- @config.logger.debug("#{LOG_LABEL} `notice.to_json` failed: #{ex.to_s.chomp}")
84
+ @config.logger.debug("#{LOG_LABEL} `notice.to_json` failed: #{ex.class}: #{ex}")
85
85
  else
86
86
  return json if json && json.bytesize <= MAX_NOTICE_SIZE
87
87
  end
88
88
 
89
- truncate_payload
89
+ break if truncate_payload.zero?
90
90
  end
91
91
  end
92
92
 
@@ -188,7 +188,16 @@ module Airbrake
188
188
  @truncator.truncate_object(@modifiable_payload[key])
189
189
  end
190
190
 
191
- @truncator.reduce_max_size
191
+ new_max_size = @truncator.reduce_max_size
192
+ if new_max_size.zero?
193
+ @config.logger.error(
194
+ "#{LOG_LABEL} truncation failed. File an issue at " \
195
+ "https://github.com/airbrake/airbrake-ruby " \
196
+ "and attach the following payload: #{payload}"
197
+ )
198
+ end
199
+
200
+ new_max_size
192
201
  end
193
202
  end
194
203
  end
@@ -23,6 +23,14 @@ module Airbrake
23
23
  def send(notice, endpoint = @config.endpoint)
24
24
  response = nil
25
25
  req = build_post_request(endpoint, notice)
26
+
27
+ if req.body.nil?
28
+ @config.logger.error(
29
+ "#{LOG_LABEL} notice was not sent because of missing body"
30
+ )
31
+ return
32
+ end
33
+
26
34
  https = build_https(endpoint)
27
35
 
28
36
  begin
@@ -3,5 +3,5 @@
3
3
  module Airbrake
4
4
  ##
5
5
  # @return [String] the library version
6
- AIRBRAKE_RUBY_VERSION = '1.3.0'.freeze
6
+ AIRBRAKE_RUBY_VERSION = '1.3.1'.freeze
7
7
  end
@@ -65,6 +65,27 @@ RSpec.describe Airbrake::Notice do
65
65
  include_examples 'payloads', 300, small_msg
66
66
  end
67
67
 
68
+ context "when truncation failed" do
69
+ it "returns nil" do
70
+ expect_any_instance_of(Airbrake::PayloadTruncator).
71
+ to receive(:reduce_max_size).and_return(0)
72
+
73
+ encoded = Base64.encode64("\xD3\xE6\xBC\x9D\xBA").encode!('ASCII-8BIT')
74
+ bad_string = Base64.decode64(encoded)
75
+
76
+ ex = AirbrakeTestError.new
77
+
78
+ backtrace = []
79
+ 10.times { backtrace << "bin/rails:3:in `<#{bad_string}>'" }
80
+ ex.set_backtrace(backtrace)
81
+
82
+ config = Airbrake::Config.new(logger: Logger.new('/dev/null'))
83
+ notice = described_class.new(config, ex)
84
+
85
+ expect(notice.to_json).to be_nil
86
+ end
87
+ end
88
+
68
89
  describe "object replacement with its string version" do
69
90
  let(:klass) { Class.new {} }
70
91
  let(:ex) { AirbrakeTestError.new }
@@ -10,7 +10,7 @@ RSpec.describe Airbrake::PayloadTruncator do
10
10
  @truncator = described_class.new(max_size, Logger.new('/dev/null'))
11
11
  end
12
12
 
13
- describe ".truncate_error" do
13
+ describe "#truncate_error" do
14
14
  let(:error) do
15
15
  { type: 'AirbrakeTestError', message: 'App crashed!', backtrace: [] }
16
16
  end
@@ -89,7 +89,7 @@ RSpec.describe Airbrake::PayloadTruncator do
89
89
  end
90
90
  end
91
91
 
92
- describe ".truncate_object" do
92
+ describe "#truncate_object" do
93
93
  describe "given a hash with short values" do
94
94
  let(:params) do
95
95
  { bingo: 'bango', bongo: 'bish', bash: 'bosh' }
@@ -15,7 +15,7 @@ RSpec.describe Airbrake::SyncSender do
15
15
  it "catches exceptions raised when sending" do
16
16
  stdout = StringIO.new
17
17
  config = Airbrake::Config.new(logger: Logger.new(stdout))
18
- sender = described_class.new config
18
+ sender = described_class.new(config)
19
19
  notice = Airbrake::Notice.new(config, AirbrakeTestError.new)
20
20
  https = double("foo")
21
21
  allow(sender).to receive(:build_https).and_return(https)
@@ -23,5 +23,29 @@ RSpec.describe Airbrake::SyncSender do
23
23
  expect(sender.send(notice)).to be_nil
24
24
  expect(stdout.string).to match(/ERROR -- : .+ HTTP error: foo/)
25
25
  end
26
+
27
+ context "when request body is nil" do
28
+ it "doesn't send a notice" do
29
+ expect_any_instance_of(Airbrake::PayloadTruncator).
30
+ to receive(:reduce_max_size).and_return(0)
31
+
32
+ encoded = Base64.encode64("\xD3\xE6\xBC\x9D\xBA").encode!('ASCII-8BIT')
33
+ bad_string = Base64.decode64(encoded)
34
+
35
+ ex = AirbrakeTestError.new
36
+ backtrace = []
37
+ 10.times { backtrace << "bin/rails:3:in `<#{bad_string}>'" }
38
+ ex.set_backtrace(backtrace)
39
+
40
+ stdout = StringIO.new
41
+ config = Airbrake::Config.new(logger: Logger.new(stdout))
42
+
43
+ sender = described_class.new(config)
44
+ notice = Airbrake::Notice.new(config, ex)
45
+
46
+ expect(sender.send(notice)).to be_nil
47
+ expect(stdout.string).to match(/ERROR -- : .+ notice was not sent/)
48
+ end
49
+ end
26
50
  end
27
51
  end
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: 1.3.0
4
+ version: 1.3.1
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: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec