Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor child pad removed default error message #581

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 additions & 0 deletions lib/membrane/exceptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ 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. For example it could happen due to removing #{inspect(child)}'s child linked to the #{inspect(child)}'s inner pad or by removing link between #{inspect(child)} and its child.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we split it into two lines?


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