From 1de0b861af70af59d2ee4ff8f4c045d9ca3c910c Mon Sep 17 00:00:00 2001 From: Kuba Suder Date: Mon, 17 Aug 2026 19:32:50 +0200 Subject: [PATCH] check if op == -1 for error messages --- lib/skyfall/firehose/message.rb | 10 ++++++---- spec/firehose/ex_invalid_message.rb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/skyfall/firehose/message.rb b/lib/skyfall/firehose/message.rb index 39fc5f9..24a2b07 100644 --- a/lib/skyfall/firehose/message.rb +++ b/lib/skyfall/firehose/message.rb @@ -187,16 +187,18 @@ module Skyfall raise DecodeError.new("Invalid object type: #{type.inspect}") unless type.is_a?(Hash) raise DecodeError.new("Invalid object type: #{data.inspect}") unless data.is_a?(Hash) + raise DecodeError.new("Missing data: #{type.inspect}") unless type['op'] + raise DecodeError.new("Invalid object type: #{type['op'].inspect}") unless type['op'].is_a?(Integer) - if data['error'] + if type['op'] == -1 && data['error'] raise SubscriptionError.new(data['error'], data['message']) + elsif type['op'] != 1 + raise UnsupportedError.new("Unexpected version: #{type['op']}") end - raise DecodeError.new("Missing data: #{type.inspect}") unless type['op'] && type['t'] - raise DecodeError.new("Invalid object type: #{type['op'].inspect}") unless type['op'].is_a?(Integer) + raise DecodeError.new("Missing data: #{type.inspect}") unless type['t'] raise DecodeError.new("Invalid object type: #{type['t'].inspect}") unless type['t'].is_a?(String) raise DecodeError.new("Invalid message type: #{type['t'].inspect}") unless type['t'].start_with?('#') - raise UnsupportedError.new("Unsupported version: #{type['op']}") unless type['op'] == 1 [type, data] end diff --git a/spec/firehose/ex_invalid_message.rb b/spec/firehose/ex_invalid_message.rb index 2e29e4b..fcee94f 100644 --- a/spec/firehose/ex_invalid_message.rb +++ b/spec/firehose/ex_invalid_message.rb @@ -69,7 +69,7 @@ shared_examples_for "invalid firehose message" do it "should raise an error if type object's op is not equal 1" do data[0]['op'] = 2 - expect { build_message(cbor) }.to raise_error(Skyfall::UnsupportedError, /Unsupported version/) + expect { build_message(cbor) }.to raise_error(Skyfall::UnsupportedError, /Unexpected version/) end end end -- 2.51.2