Skip to content

Commit

Permalink
Use Logger.error to print original error while handling action return…
Browse files Browse the repository at this point in the history
…ed by callback. Improve formatting.
  • Loading branch information
varsill committed Jun 10, 2024
1 parent c7afa10 commit 38ae233
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/membrane/core/callback_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ defmodule Membrane.Core.CallbackHandler do
Error handling actions returned by callback #{inspect(state.module)}.#{callback}
""")

log_debug_orginal_error(actions, e, __STACKTRACE__)
log_error_orginal_error(actions, e, __STACKTRACE__)

reraise e, __STACKTRACE__
end
Expand All @@ -197,10 +197,11 @@ defmodule Membrane.Core.CallbackHandler do
rescue
e ->
Membrane.Logger.error("""
Error handling action #{inspect(action)} returned by callback #{inspect(state.module)}.#{callback}
Error handling action returned by callback #{inspect(state.module)}.#{callback}.
Action: #{inspect(action, pretty: true)}
""")

log_debug_orginal_error(action, e, __STACKTRACE__)
log_error_orginal_error(action, e, __STACKTRACE__)

reraise e, __STACKTRACE__
end
Expand All @@ -212,15 +213,12 @@ defmodule Membrane.Core.CallbackHandler do
# We log it, because sometimes, for some reason, crashing process doesn't cause
# printing error logs on stderr, so this debug log allows us to get some info
# about what happened in case of process crash
defp log_debug_orginal_error(action_or_actions, error, stacktrace) do
defp log_error_orginal_error(action_or_actions, error, stacktrace) do
action_or_actions =
if(is_list(action_or_actions), do: "actions ", else: "action ") <>
inspect(action_or_actions, limit: :infinity)

Membrane.Logger.debug("""
Error while handling #{action_or_actions}
Orginal error:
Membrane.Logger.error("""
#{inspect(error, pretty: true, limit: :infinity)}
#{Exception.format_stacktrace(stacktrace)}
""")
Expand Down

0 comments on commit 38ae233

Please sign in to comment.