@@ -924,38 +924,14 @@ defmodule UndefinedFunctionError do
924
924
925
925
defp message ( :"function not exported" , module , function , arity ) do
926
926
formatted_fun = Exception . format_mfa ( module , function , arity )
927
- fun_message = "function #{ formatted_fun } is undefined or private"
928
- behaviour_hint = behaviour_hint ( module , function , arity )
929
- { fun_message <> behaviour_hint , true }
927
+ { "function #{ formatted_fun } is undefined or private" , true }
930
928
end
931
929
932
930
defp message ( reason , module , function , arity ) do
933
931
formatted_fun = Exception . format_mfa ( module , function , arity )
934
932
{ "function #{ formatted_fun } is undefined (#{ reason } )" , false }
935
933
end
936
934
937
- defp behaviour_hint ( module , function , arity ) do
938
- case behaviours_for ( module ) do
939
- [ ] ->
940
- ""
941
-
942
- behaviours ->
943
- case Enum . find ( behaviours , & expects_callback? ( & 1 , function , arity ) ) do
944
- nil -> ""
945
- behaviour -> ", but the behaviour #{ inspect ( behaviour ) } expects it to be present"
946
- end
947
- end
948
- rescue
949
- # In case the module was removed while we are computing this
950
- UndefinedFunctionError ->
951
- [ ]
952
- end
953
-
954
- defp expects_callback? ( behaviour , function , arity ) do
955
- callbacks = behaviour . behaviour_info ( :callbacks )
956
- Enum . member? ( callbacks , { function , arity } )
957
- end
958
-
959
935
@ impl true
960
936
def blame ( exception , stacktrace ) do
961
937
% { reason: reason , module: module , function: function , arity: arity } = exception
@@ -970,7 +946,8 @@ defmodule UndefinedFunctionError do
970
946
end
971
947
972
948
defp hint ( module , function , arity , true ) do
973
- hint_for_loaded_module ( module , function , arity , nil )
949
+ behaviour_hint ( module , function , arity ) <>
950
+ hint_for_loaded_module ( module , function , arity , nil )
974
951
end
975
952
976
953
defp hint ( _module , _function , _arity , _loaded? ) do
@@ -1021,12 +998,33 @@ defmodule UndefinedFunctionError do
1021
998
[ " * " , Code.Identifier . inspect_as_function ( fun ) , ?/ , Integer . to_string ( arity ) , ?\n ]
1022
999
end
1023
1000
1001
+ defp behaviour_hint ( module , function , arity ) do
1002
+ case behaviours_for ( module ) do
1003
+ [ ] ->
1004
+ ""
1005
+
1006
+ behaviours ->
1007
+ case Enum . find ( behaviours , & expects_callback? ( & 1 , function , arity ) ) do
1008
+ nil -> ""
1009
+ behaviour -> ", but the behaviour #{ inspect ( behaviour ) } expects it to be present"
1010
+ end
1011
+ end
1012
+ rescue
1013
+ # In case the module was removed while we are computing this
1014
+ UndefinedFunctionError -> ""
1015
+ end
1016
+
1024
1017
defp behaviours_for ( module ) do
1025
1018
:attributes
1026
1019
|> module . module_info ( )
1027
1020
|> Keyword . get ( :behaviour , [ ] )
1028
1021
end
1029
1022
1023
+ defp expects_callback? ( behaviour , function , arity ) do
1024
+ callbacks = behaviour . behaviour_info ( :callbacks )
1025
+ Enum . member? ( callbacks , { function , arity } )
1026
+ end
1027
+
1030
1028
defp exports_for ( module ) do
1031
1029
if function_exported? ( module , :__info__ , 1 ) do
1032
1030
module . __info__ ( :macros ) ++ module . __info__ ( :functions )
0 commit comments