Skip to content

Commit

Permalink
raise error to be captured on parser failure
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Oct 14, 2024
1 parent 4ecda28 commit 232da49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/lib/raw_mqtt_message_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def initialize
end

def parse(message)
parser.parse(self.convert_to_ascii(message.strip))&.to_hash
message = parser.parse(self.convert_to_ascii(message.strip))&.to_hash
raise "Message not parsed: #{message}" unless message
return message
end

private
Expand Down
5 changes: 2 additions & 3 deletions spec/lib/raw_mqtt_message_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@
expect(parsed).to eq({ data: [ { recorded_at: "2024-09-25T13:19:38Z", sensors: [{id: "100", value: "-2000.12345"}] }]})
end

it "returns nil if no valid message parsed" do
it "raises an error if no valid message parsed" do
message = "ceci n'est pas un message"
parsed = parser.parse(message)
expect(parsed).to eq(nil)
expect {parser.parse(message)}.to raise_error(RuntimeError)
end

it "parses timestamps at any position in the packet" do
Expand Down

0 comments on commit 232da49

Please sign in to comment.