Skip to content

Commit

Permalink
fix: update kafee consumer handle_failure/2 fn (#119)
Browse files Browse the repository at this point in the history
## Related Ticket(s)

N/A

## Checklist

<!--
For each bullet, ensure your pr meets the criteria and write a note
explaining how this PR relates. Mark them as complete as they are done.
All top-level checkboxes should be checked regardless of their relevance
to the pr with a note explaining whether they are relevant or not.
-->

- [X] Code conforms to the [Elixir
Styleguide](https://github.com/christopheradams/elixir_style_guide)

## Problem

The built in `Kafee.Consumer.handle_failure/2` function raises an error
which causes problems down the line. It should instead return an `:ok`
like the behaviour specifies.

## Details

Change `raise RuntimeError` to `Logger.error`

---------

Co-authored-by: Jonathan Thomas <[email protected]>
  • Loading branch information
btkostner and jondthomas authored Dec 13, 2024
1 parent 3adffb8 commit 4c12df7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/kafee/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ defmodule Kafee.Consumer do
@doc false
defmacro __using__(opts \\ []) do
quote location: :keep, bind_quoted: [opts: opts, module: __CALLER__.module] do
require Logger

@behaviour Kafee.Consumer

@doc false
Expand Down Expand Up @@ -227,19 +229,15 @@ defmodule Kafee.Consumer do

@impl Kafee.Consumer
def handle_failure(error, %Kafee.Consumer.Message{} = message) do
inspected_message = inspect(message)
inspected_error = inspect(error)

raise RuntimeError,
message: """
Logger.error(
"""
An error has been raised while processing a Kafka message.
Message:
#{inspected_message}
Error:
#{inspected_error}
"""
#{inspect(error)}
""",
error: error
)
end

defoverridable child_spec: 1, handle_message: 1, handle_failure: 2
Expand Down

0 comments on commit 4c12df7

Please sign in to comment.