Richardm
String.contains? not outputting what I expect it to
Hi,
I have the following code, and even though I can see (via the inspect) that the response_body does contain one of the strings I’m looking for, I’m not getting the “Waiting for Daemon to be ready message”?
Any ideas what I’m doing wrong please?
case HTTPoison.post(url, body, headers) do
{:ok, %{body: response_body}} →
IO.inspect(response_body)
if String.contains?(response_body, "Loading") ||
String.contains?(response_body, "Preparing databases") ||
String.contains?(response_body, "Rewinding") ||
String.contains?(response_body, "RPC server started") ||
String.contains?(response_body, "Verifying") do
Logger.info("Waiting for Daemon to be ready, attempt #{attempt}")
Process.sleep(3000)
{:cont, {:error, :wrong_response}}
Most Liked
kip
There are a couple of differences:
||operates ontruthinessorfalsenessin the Elixir sense. That is,nilandfalseare consideredfalsyand everything else istruthy.||will short circuit. If the left hand side expression isfalsythen the right hand side expression is not evaluated.orexpressions must be booleans (true or false)ordoes not short circuit||is not available for use in guard expressions.
That means that || and or both have a place in the language.
mudasobwa
These both statements are not precisely correct, because Kernel.or/2 gets translated to :erlang.orelse/2, not to :erlang.or/2.
- LHO of
or/2must be a boolean, the RHO might be anything; or/2does short circuit.
If one wants the erlangish behaviour, they should opt in for :erlang.or/2.
garrison
To add on to the above, make sure you check out the operators reference in the docs and click on any you’re curious about. One of the cool things about Elixir is that pretty much every language construct is implemented as a function or macro and they all have excellent docs.
rscheffer
What’s the output of Logger.level()? If it’s not info or debug, nothing will be logged
pxp9
I think you can figure out what’s happening easily if you try to open a Elixir interpreter with your application.
If it is a Phoenix app
iex -S mix phx.server
If not
iex -S mix
Then, you should be able to execute the Elixir Code from your function there, or you should be able to just copy paste an expression which you don’t know what should be the behavior.







