Skip to content

Commit ff856ff

Browse files
committed
fix: Adds ResultError and raises on non-monad results
1 parent 3e1d659 commit ff856ff

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/leopard/errors.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module Rubyists
44
module Leopard
55
class Error < StandardError; end
66
class ConfigurationError < Error; end
7+
class ResultError < Error; end
78
end
89
end

lib/leopard/nats_api_server.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,22 @@ def handle_message(raw_msg, handler)
202202

203203
# Processes the result of the handler execution.
204204
#
205+
#
205206
# @param wrapper [MessageWrapper] The message wrapper containing the raw message.
206207
# @param result [Dry::Monads::Result] The result of the handler execution.
207208
#
208209
# @return [void]
210+
# @raise [ResultError] If the result is not a Success or Failure monad.
209211
def process_result(wrapper, result)
210212
case result
211213
in Dry::Monads::Success
212214
wrapper.respond(result.value!)
213215
in Dry::Monads::Failure
214216
logger.error 'Error processing message: ', result.failure
215217
wrapper.respond_with_error(result.failure)
218+
else
219+
logger.error('Unexpected result: ', result:)
220+
raise ResultError, "Unexpected Response from Handler, must respond with a Success or Failure monad: #{result}"
216221
end
217222
end
218223
end

0 commit comments

Comments
 (0)