From 44550ec657ea4739bc4afac03d923ec6aaab2724 Mon Sep 17 00:00:00 2001 From: Adam Lancaster Date: Mon, 23 May 2022 09:59:00 +0100 Subject: [PATCH] Update utils.ex The [docs for ensure_compiled](https://hexdocs.pm/elixir/1.13/Code.html#ensure_compiled/1) specifically warn against doing this. To quote: > If the module being checked is currently in a compiler deadlock, this function returns {:error, :unavailable}. Unavailable doesn't necessarily mean the module doesn't exist, just that it is not currently available, but it (or may not) become available in the future. Therefore, if you can only continue if the module is available, use ensure_compiled!/1 instead. In particular, do not do this: ```elixir case Code.ensure_compiled(module) do {:module, _} -> module {:error, _} -> raise ... end ``` --- lib/hammox/utils.ex | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/hammox/utils.ex b/lib/hammox/utils.ex index 1c0de49..209be9b 100644 --- a/lib/hammox/utils.ex +++ b/lib/hammox/utils.ex @@ -40,14 +40,6 @@ defmodule Hammox.Utils do end def check_module_exists(module) do - case Code.ensure_compiled(module) do - {:module, _} -> - true - - _ -> - raise(ArgumentError, - message: "Could not find module #{module_to_string(module)}." - ) - end + Code.ensure_compiled!(module) end end