elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.52k stars 3.38k forks source link

Absolute paths in stacktrace #2211

Closed alco closed 10 years ago

alco commented 10 years ago

Isn't Elixir supposed to output relative paths? I thought it did so before 0.13.1.

λ mix test
== Compilation error on file lib/wyvern/helpers.ex ==
** (ArgumentError) dynamic access cannot be invoked inside match and guard clauses
    (elixir) lib/kernel.ex:2659: Kernel."MACRO-access"/3
    (elixir) /Users/alco/home/projects/wyvern/lib/wyvern/helpers.ex:17: Kernel.access/2
    /Users/alco/home/projects/wyvern/lib/wyvern/helpers.ex:17: Wyvern.View.Helpers.render/2
    (elixir) /Users/alco/home/projects/wyvern/lib/wyvern/helpers.ex:13: Kernel.cond/1
    /Users/alco/home/projects/wyvern/lib/wyvern/helpers.ex:13: Wyvern.View.Helpers.render/2

Elixir version https://github.com/elixir-lang/elixir/commit/e343f210f605330ac2bafe6874e58bb7b60613bd.

ericmj commented 10 years ago

Maybe it doesnt work for compile time stacktraces. Do you get relative paths for runtime stacktraces?

josevalim commented 10 years ago

I just tried to reproduce this but i could not:

1) test cookies/1 loaded early (Plug.ConnTest)
 ** (FunctionClauseError) no function clause matching in URI.parse/1
 stacktrace:
   (elixir) lib/uri.ex:221: URI.parse(:omg)
   (plug) lib/plug/adapters/test/conn.ex:8: Plug.Adapters.Test.Conn.conn/4
   test/plug/conn_test.exs:304: Plug.ConnTest."test cookies/1 loaded early"/1

Note plug stacktraces (it was recompiled) are still relative. Is this an umbrella project or are you compiling it in a non-conventional way?

ericmj commented 10 years ago

@josevalim That looks like a runtime error. Have you tried with an error that occurs at compile, like using access in a guard as in @alco's example?

josevalim commented 10 years ago

Ah, good call. @alco is this app open source? Or can you provide a simple way to reproduce it? I would love to take a look... I have also noticed this stacktrace is wrong:

 (elixir) /Users/alco/home/projects/wyvern/lib/wyvern/helpers.ex:17: Kernel.access/2

There is definitely no Kernel.access/2 there (and it is not part of elixir).

alco commented 10 years ago

I'll try narrowing it down to a small code example.

alco commented 10 years ago
defmodule M do
  def something(opts) do
    cond do
      opts[:tag]=tag -> :ok
    end
  end
end
λ elixirc absolute_paths.ex
== Compilation error on file absolute_paths.ex ==
** (ArgumentError) dynamic access cannot be invoked inside match and guard clauses
    (elixir) lib/kernel.ex:2658: Kernel."MACRO-access"/3
    (elixir) /Users/alco/home/projects/wyvern/absolute_paths.ex:4: Kernel.access/2
    /Users/alco/home/projects/wyvern/absolute_paths.ex:4: M.something/1
    (elixir) /Users/alco/home/projects/wyvern/absolute_paths.ex:4: Kernel.!/1
    /Users/alco/home/projects/wyvern/absolute_paths.ex:4: M.something/1
    (elixir) /Users/alco/home/projects/wyvern/absolute_paths.ex:3: Kernel.cond/1
    /Users/alco/home/projects/wyvern/absolute_paths.ex:3: M.something/1
josevalim commented 10 years ago

That is beautiful. Thanks!

josevalim commented 10 years ago

What about this stacktrace?

== Compilation error on file lib/sample.ex ==
** (ArgumentError) dynamic access cannot be invoked inside match and guard clauses
    (elixir) expanding macro: Kernel.access/2
    lib/sample.ex:12: Sample.something/1
    (elixir) expanding macro: Kernel.!/1
    lib/sample.ex:12: Sample.something/1
    (elixir) expanding macro: Kernel.cond/1
    lib/sample.ex:11: Sample.something/1
alco commented 10 years ago

:+1: