From 7f6ac6dcdf1a45a6a644414ce1c3b4b676e154a5 Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Thu, 20 Jul 2023 14:40:10 +0200 Subject: [PATCH] Fix dialyzer issue --- lib/membrane/bin.ex | 8 +------- lib/membrane/core/callback_handler.ex | 7 ++++++- lib/membrane/core/parent.ex | 20 -------------------- lib/membrane/exceptions.ex | 23 +++++++++++++++++++++++ lib/membrane/pipeline.ex | 8 +------- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/lib/membrane/bin.ex b/lib/membrane/bin.ex index 3e0d92870..3937eeb38 100644 --- a/lib/membrane/bin.ex +++ b/lib/membrane/bin.ex @@ -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, @@ -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 diff --git a/lib/membrane/core/callback_handler.ex b/lib/membrane/core/callback_handler.ex index 7b0746cbe..30cb8d3bc 100644 --- a/lib/membrane/core/callback_handler.ex +++ b/lib/membrane/core/callback_handler.ex @@ -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 diff --git a/lib/membrane/core/parent.ex b/lib/membrane/core/parent.ex index 0a4ba5183..4f0fb5f8a 100644 --- a/lib/membrane/core/parent.ex +++ b/lib/membrane/core/parent.ex @@ -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 diff --git a/lib/membrane/exceptions.ex b/lib/membrane/exceptions.ex index df28edb6f..2ce441f42 100644 --- a/lib/membrane/exceptions.ex +++ b/lib/membrane/exceptions.ex @@ -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) diff --git a/lib/membrane/pipeline.ex b/lib/membrane/pipeline.ex index b77255588..9a99a3392 100644 --- a/lib/membrane/pipeline.ex +++ b/lib/membrane/pipeline.ex @@ -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, @@ -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