@@ -41,9 +41,6 @@ defmodule Ethers.Contract do
4141 - `[{function_name :: atom(), skip_docs :: boolean()}]`: Specify for each function.
4242 """
4343
44- require Ethers.ContractHelpers
45- require Logger
46-
4744 import Ethers.ContractHelpers
4845
4946 @ default_constructor % {
@@ -362,18 +359,28 @@ defmodule Ethers.Contract do
362359 |> Enum . map ( fn % { selectors: [ selector ] } -> selector end )
363360 |> Enum . map ( & { & 1 . method_id , Module . concat ( [ mod , Errors , & 1 . function ] ) } )
364361 |> Enum . into ( % { } )
365- |> Macro . escape ( )
366-
367- quote context: errors_module , location: :keep do
368- @ doc false
369- def find_and_decode ( << error_id :: binary - 4 , _ :: binary >> = error_data ) do
370- case Map . fetch ( error_mappings ( ) , error_id ) do
371- { :ok , module } -> module . decode ( error_data )
372- :error -> { :error , :undefined_error }
362+
363+ if map_size ( error_mappings ) == 0 do
364+ quote context: errors_module , location: :keep do
365+ @ doc false
366+ def find_and_decode ( << _error_id :: binary - 4 , _ :: binary >> ) do
367+ { :error , :undefined_error }
373368 end
374369 end
370+ else
371+ error_mappings = Macro . escape ( error_mappings )
372+
373+ quote context: errors_module , location: :keep do
374+ @ doc false
375+ def find_and_decode ( << error_id :: binary - 4 , _ :: binary >> = error_data ) do
376+ case Map . fetch ( error_mappings ( ) , error_id ) do
377+ { :ok , module } -> module . decode ( error_data )
378+ :error -> { :error , :undefined_error }
379+ end
380+ end
375381
376- defp error_mappings , do: unquote ( error_mappings )
382+ defp error_mappings , do: unquote ( error_mappings )
383+ end
377384 end
378385 end
379386
0 commit comments