Skip to content

Commit

Permalink
Fix dialyzer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Jul 20, 2023
1 parent f94b907 commit 7f6ac6d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
8 changes: 1 addition & 7 deletions lib/membrane/bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,6 @@ defmodule Membrane.Bin do
@impl true
def handle_terminate_request(_ctx, state), do: {[terminate: :normal], state}

@impl true
def handle_child_pad_removed(child, pad, _ctx, _state) do
raise Membrane.Core.Parent.child_pad_removed_error_message(child, pad, __MODULE__)
end

defoverridable handle_init: 2,
handle_pad_added: 3,
handle_pad_removed: 3,
Expand All @@ -384,8 +379,7 @@ defmodule Membrane.Bin do
handle_child_notification: 4,
handle_parent_notification: 3,
handle_crash_group_down: 3,
handle_terminate_request: 2,
handle_child_pad_removed: 4
handle_terminate_request: 2
end
end

Expand Down
7 changes: 6 additions & 1 deletion lib/membrane/core/callback_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ defmodule Membrane.Core.CallbackHandler do
e in UndefinedFunctionError ->
with %{module: ^module, function: ^callback, arity: arity} <- e do
reraise CallbackError,
[kind: :not_implemented, callback: {module, callback}, arity: arity],
[
kind: :not_implemented,
callback: {module, callback},
arity: arity,
args: args
],
__STACKTRACE__
end

Expand Down
20 changes: 0 additions & 20 deletions lib/membrane/core/parent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,4 @@ defmodule Membrane.Core.Parent do
@moduledoc false

@type state :: Membrane.Core.Bin.State.t() | Membrane.Core.Pipeline.State.t()

@spec child_pad_removed_error_message(Child.name(), Pad.ref(), module()) :: String.t()
def child_pad_removed_error_message(child, pad, component_module) do
component_type_string =
cond do
Membrane.Pipeline.pipeline?(component_module) -> "Pipeline"
Membrane.Bin.bin?(component_module) -> "Bin"
end

callback_ref = "`c:Membrane.#{component_type_string}.handle_child_pad_removed/4`"

"""
Bin #{inspect(child)} removed its pad #{inspect(pad)}, but callback #{callback_ref} is not implemented in #{inspect(component_module)}.
This means, that `#{inspect(child)} removed the pad on its own, without knowledge of its parent. It could be done, by, for example,
removing #{inspect(child)}'s child linked to the #{inspect(child)}'s inner pad or by removing link between #{inspect(child)} and its child.
If you want to handle this scenario, implement #{callback_ref} callback in #{inspect(component_module)}.
"""
end
end
23 changes: 23 additions & 0 deletions lib/membrane/exceptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ defmodule Membrane.CallbackError do
%__MODULE__{message: msg}
end

defp mk_exception(:not_implemented, {module, :handle_child_pad_removed}, opts) do
[child, pad, _context, _custom_state] = Keyword.fetch!(opts, :args)

component_type_string =
cond do
Membrane.Pipeline.pipeline?(module) -> "Pipeline"
Membrane.Bin.bin?(module) -> "Bin"
end

callback_ref = "`c:Membrane.#{component_type_string}.handle_child_pad_removed/4`"

msg = """
Bin #{inspect(child)} removed its pad #{inspect(pad)}, but callback #{callback_ref} is not implemented in #{inspect(module)}.
This means, that `#{inspect(child)} removed the pad on its own, without knowledge of its parent. It could be done, by, for example,
removing #{inspect(child)}'s child linked to the #{inspect(child)}'s inner pad or by removing link between #{inspect(child)} and its child.
If you want to handle this scenario, implement #{callback_ref} callback in #{inspect(module)}.
"""

%__MODULE__{message: msg}
end

defp mk_exception(:not_implemented, {module, fun}, opts) do
arity = Keyword.fetch!(opts, :arity)

Expand Down
8 changes: 1 addition & 7 deletions lib/membrane/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,6 @@ defmodule Membrane.Pipeline do
@impl true
def handle_terminate_request(_ctx, state), do: {[terminate: :normal], state}

@impl true
def handle_child_pad_removed(child, pad, _ctx, _state) do
raise Membrane.Core.Parent.child_pad_removed_error_message(child, pad, __MODULE__)
end

defoverridable child_spec: 1,
handle_init: 2,
handle_setup: 2,
Expand All @@ -573,8 +568,7 @@ defmodule Membrane.Pipeline do
handle_child_notification: 4,
handle_crash_group_down: 3,
handle_call: 3,
handle_terminate_request: 2,
handle_child_pad_removed: 4
handle_terminate_request: 2
end
end
end

0 comments on commit 7f6ac6d

Please sign in to comment.