Cond statement not providing stack trace

Does anyone know why the cond does not provide a stack trace (anymore if it did in the past, do not recall).

Example of a failing case and cond.

iex(1)> case :ok do :error-> :ok end
** (CaseClauseError) no case clause matching: :ok
(stdlib) erl_eval.erl:968: :erl_eval.case_clauses/6
(iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
(iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
(iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3
(iex) lib/iex/evaluator.ex:103: IEx.Evaluator.loop/1
(iex) lib/iex/evaluator.ex:27: IEx.Evaluator.init/4

iex(1)> cond do :ok==:error -> :ok end
** (CondClauseError) no cond clause evaluated to a truthy value

Where is the stack trace!?

1 Like

Here:

** (CondClauseError) no cond clause evaluated to a truthy value
    Foo.run/0
    (elixir) lib/code.ex:813: Code.require_file/2

Just create module and make it fail there:

defmodule Foo do
  def run do
    cond do
      :ok == :error -> :ok
    end
  end
end

Foo.run
1 Like

This shows there is no stack trace as I mentioned above, it says it failed on Foo.run/0, where is the line number of Foo.run/0 plus module its located in.

Also I get the same as I posted

iex(9)> defmodule Foo do
...(9)>   def run do
...(9)>     cond do
...(9)>       :ok == :error -> :ok
...(9)>     end
...(9)>   end
...(9)> end
warning: this check/guard will always yield the same result
  iex:12

{:module, Foo,
 <<70, 79, 82, 49, 0, 0, 4, 76, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 139,
   0, 0, 0, 15, 10, 69, 108, 105, 120, 105, 114, 46, 70, 111, 111, 8, 95, 95,
   105, 110, 102, 111, 95, 95, 7, 99, 111, ...>>, {:run, 0}}
iex(10)> Foo.run
** (CondClauseError) no cond clause evaluated to a truthy value
    Foo.run/0
iex(10)> 

1 Like

I sent a PR with a fix for this issue: https://github.com/elixir-lang/elixir/pull/9730.

3 Likes