@@ -922,19 +922,22 @@ defmodule Mox do
922922
923923 @ doc false
924924 def __dispatch__ ( mock , name , arity , args ) do
925- case fetch_fun_to_dispatch ( [ self ( ) | caller_pids ( ) ] , { mock , name , arity } ) do
925+ caller_pids = caller_pids ( )
926+
927+ case fetch_fun_to_dispatch ( [ self ( ) | caller_pids ] , { mock , name , arity } ) do
926928 :no_expectation ->
927929 mfa = Exception . format_mfa ( mock , name , arity )
928930
929931 raise UnexpectedCallError ,
930- "no expectation defined for #{ mfa } in #{ format_process ( ) } with args #{ inspect ( args ) } "
932+ "no expectation found for #{ mfa } in #{ format_process ( caller_pids , true ) } " <>
933+ "with args #{ inspect ( args ) } "
931934
932935 { :out_of_expectations , count } ->
933936 mfa = Exception . format_mfa ( mock , name , arity )
934937
935938 raise UnexpectedCallError ,
936939 "expected #{ mfa } to be called #{ times ( count ) } but it has been " <>
937- "called #{ times ( count + 1 ) } in #{ format_process ( ) } "
940+ "called #{ times ( count + 1 ) } in #{ format_process ( caller_pids , false ) } "
938941
939942 { :remote , fun_to_call } ->
940943 # It's possible that Mox.Server is running on a remote node in the cluster. Since the
@@ -954,14 +957,17 @@ defmodule Mox do
954957 defp times ( 1 ) , do: "once"
955958 defp times ( n ) , do: "#{ n } times"
956959
957- defp format_process do
958- callers = caller_pids ( )
959-
960+ defp format_process ( callers , report_dead_callers? ) do
960961 "process #{ inspect ( self ( ) ) } " <>
961- if Enum . empty? ( callers ) do
962- ""
963- else
964- " (or in its callers #{ inspect ( callers ) } )"
962+ cond do
963+ Enum . empty? ( callers ) ->
964+ ""
965+
966+ report_dead_callers? and Enum . all? ( callers , & ( not Process . alive? ( & 1 ) ) ) ->
967+ " (or in its callers #{ inspect ( callers ) } , all of which are dead)"
968+
969+ true ->
970+ " (or in its callers #{ inspect ( callers ) } )"
965971 end
966972 end
967973
0 commit comments