Richardm

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

kip

ex_cldr Core Team

There are a couple of differences:

  • || operates on truthiness or falseness in the Elixir sense. That is, nil and false are considered falsy and everything else is truthy.
  • || will short circuit. If the left hand side expression is falsy then the right hand side expression is not evaluated.
  • or expressions must be booleans (true or false)
  • or does not short circuit
  • || is not available for use in guard expressions.

That means that || and or both have a place in the language.

mudasobwa

mudasobwa

Creator of Cure

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/2 must be a boolean, the RHO might be anything;
  • or/2 does short circuit.

If one wants the erlangish behaviour, they should opt in for :erlang.or/2.

garrison

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

rscheffer

What’s the output of Logger.level()? If it’s not info or debug, nothing will be logged

pxp9

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.

Where Next?

Popular in Troubleshooting Top

chocolatedonut
Besides (over)logging every code-path leading to Repo.insert_all, is it possible to make Postgrex and/or ecto_sql log the exact, failing ...
New
mooreryan
In a project I’m working on, I cannot get tests with breakpoints or pry working. Here is an example in a new mix project. Create a fresh...
New
wktdev
I tried to learn Elixir a few years ago and stopped. I am trying again. In the code below I have a GenServer that is started by a Superv...
New
jdj_dk
Hi everyone. I’m trying to setup a small cluster with three nodes. I’m using libcluster as I have before. But my nodes doesn’t have a us...
New
pikdum
Hello, I’m trying to upgrade a pretty large project from Elixir 1.18.4 to Elixir 1.19.1 (1321 modules), but seeing some compiler warning...
New
apoorv-2204
The Issue of Enums in Elixir Elixir doesn’t have a native enum construct, so we usually rely on atoms, strings, or macros to represent na...
New
klo
Is there any way to go from a float 1.0 to 1.00 while retaining the float() type?
New
rayex
Hi, I am using the following versions: Erlang/OTP 27 [erts-15.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns] El...
New
Richardm
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 lo...
New
runyonave
We have been stuck on this for a few days now and I am really not sure what could be missing. I can get chromic_pdf to work perfectly fin...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement