FarhanSyedain

FarhanSyedain

Io.puts and Logger not working along with errors not being dispayed

Here is my primary test file

ExUnit.start()


Ecto.Adapters.SQL.Sandbox.mode(Core.Repo, :manual)

Faker.start()


defmodule ChatBackendTest do
  use ExUnit.Case, async: true
  alias ChatBackendTest.Support.Factory

  use ChatBackendTest.Support.EctoTemplate


  require Logger
  alias Core.Schema.User


  test "create user" do

    _ = Factory.create(User, %{})

    IO.puts("Should Print this too")
#
  end



end

And here is the factory file

defmodule ChatBackendTest.Support.Factory do
  alias Authentication.Schema.User

  alias Core.Repo

  require Logger

  def create(User, attrs) do
    Logger.error("Should print on console")

    user_data =
      Keyword.merge(
        [
          phone_number: Faker.Phone.PtBr.phone(),
          uuid: Faker.UUID.v4(),
          last_seen: NaiveDateTime.utc_now(),
          registration_id: Faker.UUID.v4()
        ],
        attrs
      )

    try do
      User |> struct(user_data) |> Repo.insert(returning: true)
    rescue
      e ->
        Logger.error("Error: #{inspect(e)}")
    end
  end
end

The problem : Io.puts or any other code is working before i call the factory.create method. However after factory.create nothing is executing , when when i put a IO.puts as the first statemetn inside the create function, nothing was printed. No error was shown in the console either.

However, when i copy the create code and put it directly in the test file. The resuce thing handles the error and gives me some error on struct.

The question being, what’s wrong with elxir not showing errors. How do i make it that all the erros are logged in instead of the test being half executed.

Where Next?

Popular in Questions 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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
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

We're in Beta

About us Mission Statement