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

alexlanderzander
Hello everyone, I’m working on a blockchain project in Elixir and I’m implementing some of the core cryptography in a Rust NIF using Rus...
New
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
Ferenc
I have installed it on Phoenix 1.8.1 (without authentication or other packages and got 2 problems). I had to set up things manually the ...
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
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
jason.o
I don’t get an error directly related to Paraxial, but removing that dependency stopped the crash. Has anyone experienced a similar issu...
New
onelastdance
Hey there, Using the install script method recommended here on Ubuntu 24.04: And then running the following commands: iex> :obser...
New
klo
Is there any way to go from a float 1.0 to 1.00 while retaining the float() type?
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

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement