Skip to content

Commit

Permalink
Merge pull request #269 from North-Two-Five/Issue-268-Raise-Error
Browse files Browse the repository at this point in the history
Push raising error message
  • Loading branch information
MichaelGHSeg authored Jun 12, 2024
2 parents 8efb707 + ee68d65 commit 030da10
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
1 change: 1 addition & 0 deletions lib/segment/analytics/message_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def <<(message)
message_json_size = message_json.bytesize
if message_too_big?(message_json_size)
logger.error('a message exceeded the maximum allowed size')
raise JSONGenerationError, 'Message Exceeded Maximum Allowed Size'
else
@messages << message
@json_size += message_json_size + 1 # One byte for the comma
Expand Down
7 changes: 6 additions & 1 deletion spec/segment/analytics/message_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ class Analytics

describe '#<<' do
it 'appends messages' do
expect(subject.length).to eq(0)

subject << { 'a' => 'b' }

expect(subject.length).to eq(1)
end

it 'rejects messages that exceed the maximum allowed size' do
max_bytes = Defaults::Message::MAX_BYTES
message = { 'a' => 'b' * max_bytes }

subject << message
expect(subject.length).to eq(0)

expect { subject << message }.to raise_error(MessageBatch::JSONGenerationError)
.with_message('Message Exceeded Maximum Allowed Size')
end
end

Expand Down

0 comments on commit 030da10

Please sign in to comment.