r/elixir • • 16h ago

Reading errors in Elixir are like reading JSON

is there any better way? struggling to read the symbols elixir provides

...kind: :error

reason: %ArgumentError{

message: "errors were found at the given arguments:\n\n * 1st argument: the table identifier does not refer to an existing ETS table\n"

}

stack: [

{:ets, :select,

[

:"keys_Elixir.Hyper.Cluster.Routing",

[{{{:"$1", :supervisor}, :_, {:"$2", :_}}, [], [{{:"$1", :"$2"}}]}]

], [error_info: %{cause: :id, module: :erl_stdlib_errors}]},

{Horde.Registry, :select,

3 Upvotes

7 comments sorted by

2

u/ZukowskiHardware 16h ago

Read from the bottom up.  Most of the time they are quite descriptive.  You can usually locate the call site and trace it yourself.  

1

u/Friendly-Intern2839 16h ago

oh ok...that might help..but it quickly gets messy if there are many errors,

1

u/ZukowskiHardware 15h ago

Yeah, the JSON you are seeing is just the map structure that drives most things in elixir.  I can’t tell but it looks like you are feeding in two blank returns in a string to the first argument of a function.  

1

u/Friendly-Intern2839 15h ago

oh, i have been able to get past the error..my issue was just if there was a better to read errors

2

u/SuspiciousDepth5924 12h ago

It's mostly standard elixir datatypes, though this part:

[{{{:"$1", :supervisor}, :_, {:"$2", :_}}, [], [{{:"$1", :"$2"}}]}]

is an erlang match spec (https://www.erlang.org/doc/apps/erts/match_spec.html) . Which is the weird not-sql query language that the built-in database uses.

Basically it's [{ <rows_to_match>, [<optional_guard_clauses>], [<what_to_return>] }] here it seems to match {{variable1, :supervisor}, _, {variable2, _}} with no guards and returns {variable1, variable2} from all the matching rows, the return is wrapped in an extra tuple to tell erlang to treat it as an actual tuple instead of an instruction like {:is_float, :"$1"}.

1

u/borromakot 14h ago

If you have an exception and a stack trace, use `Exception.format`.

1

u/adamtang7 4h ago

Hmm... It's easy to read if you have enough experience on elixir. May be channel to AI to get a brief description?