Skip to content

Commit

Permalink
Log messages in default handle_info implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Nov 20, 2023
1 parent 16f803f commit ab2cf2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 10 additions & 2 deletions lib/membrane/bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule Membrane.Bin do
as an internal membrane message.
Can be used for receiving data from non-membrane processes.
By default, it ignores the received message.
By default, it logs and ignores the received message.
"""
@callback handle_info(
message :: any,
Expand Down Expand Up @@ -317,6 +317,7 @@ defmodule Membrane.Bin do
only: [def_input_pad: 2, def_output_pad: 2, def_options: 1, def_clock: 0, def_clock: 1]

require Membrane.Core.Child.PadsSpecs
require Membrane.Logger

Membrane.Core.Child.PadsSpecs.ensure_default_membrane_pads()

Expand Down Expand Up @@ -344,7 +345,14 @@ defmodule Membrane.Bin do
def handle_playing(_ctx, state), do: {[], state}

@impl true
def handle_info(message, _ctx, state), do: {[], state}
def handle_info(message, _ctx, state) do
Membrane.Logger.warning("""
Received message but no handle_info callback has been specified. Ignoring.
Message: #{inspect(message)}\
""")

{[], state}
end

@impl true
def handle_spec_started(new_children, _ctx, state), do: {[], state}
Expand Down
12 changes: 10 additions & 2 deletions lib/membrane/element/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule Membrane.Element.Base do
as an internal membrane message.
Useful for receiving ticks from timer, data sent from NIFs or other stuff.
By default, it ignores the received message.
By default, it logs and ignores the received message.
"""
@callback handle_info(
message :: any(),
Expand Down Expand Up @@ -251,6 +251,7 @@ defmodule Membrane.Element.Base do
import unquote(__MODULE__), only: [def_clock: 0, def_clock: 1, def_options: 1]

require Membrane.Core.Child.PadsSpecs
require Membrane.Logger

Membrane.Core.Child.PadsSpecs.ensure_default_membrane_pads()

Expand All @@ -274,7 +275,14 @@ defmodule Membrane.Element.Base do
def handle_playing(_context, state), do: {[], state}

@impl true
def handle_info(_message, _context, state), do: {[], state}
def handle_info(message, _context, state) do
Membrane.Logger.warning("""
Received message but no handle_info callback has been specified. Ignoring.
Message: #{inspect(message)}\
""")

{[], state}
end

@impl true
def handle_pad_added(_pad, _context, state), do: {[], state}
Expand Down
12 changes: 10 additions & 2 deletions lib/membrane/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ defmodule Membrane.Pipeline do
as an internal membrane message.
Useful for receiving data sent from NIFs or other stuff.
By default, it ignores the received message.
By default, it logs and ignores the received message.
"""
@callback handle_info(
message :: any,
Expand Down Expand Up @@ -457,6 +457,7 @@ defmodule Membrane.Pipeline do
# credo:disable-for-next-line Credo.Check.Refactor.LongQuoteBlocks
quote do
alias unquote(__MODULE__)
require Membrane.Logger
@behaviour unquote(__MODULE__)

unquote(bring_spec)
Expand Down Expand Up @@ -492,7 +493,14 @@ defmodule Membrane.Pipeline do
def handle_playing(_ctx, state), do: {[], state}

@impl true
def handle_info(message, _ctx, state), do: {[], state}
def handle_info(message, _ctx, state) do
Membrane.Logger.warning("""
Received message but no handle_info callback has been specified. Ignoring.
Message: #{inspect(message)}\
""")

{[], state}
end

@impl true
def handle_spec_started(new_children, _ctx, state), do: {[], state}
Expand Down

0 comments on commit ab2cf2e

Please sign in to comment.