kuon

kuon

Is it possible to get more context information when anonymous function doesn't match

When a function doesn’t match, for example:

    |> Multi.update(:add_something, fn %{required: obj} ->
        ...
        end)

If this is called when required is not in the multi (but can be anything like, Enum.map([1, 2, 3], fn {} -> 0 end)) I get an error like this:

     ** (FunctionClauseError) no function clause matching in anonymous fn/1 in Book.CMS.Queries.multi_ensure_list/4

     The following arguments were given to anonymous fn/1 in Book.CMS.Queries.multi_ensure_list/4:

         # 1
         ... ctx

     code: CMS.update_page_children(site.id, page_r.gid, [
     stacktrace:
       (book 0.1.0) anonymous fn/1 in Book.CMS.Queries.multi_ensure_list/4
       (ecto 3.11.2) lib/ecto/multi.ex:973: anonymous fn/5 in Ecto.Multi.operation_fun/2
       (ecto 3.11.2) lib/ecto/multi.ex:883: Ecto.Multi.apply_operation/5
       (elixir 1.17.2) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
       (ecto 3.11.2) lib/ecto/multi.ex:856: anonymous fn/5 in Ecto.Multi.apply_operations/5
       (ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:1358: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
       (db_connection 2.6.0) lib/db_connection.ex:1710: DBConnection.run_transaction/4
       (ecto 3.11.2) lib/ecto/repo/transaction.ex:18: Ecto.Repo.Transaction.transaction/4
       (book 0.1.0) lib/ecto/helpers.ex:56: Book.Ecto.Helpers.transaction/2
       test/book/cms_test.exs:98: (test)

My problem is with this line:

       (book 0.1.0) anonymous fn/1 in Book.CMS.Queries.multi_ensure_list/4

Because it is an anonymous function, there is no line number. Only thing I know is that the error was in multi_ensure_list which has like 4-5 anonymous functions like this. So it makes it hard to pinpoint.

Is there a way to improve this (only required for debugging, so I don’t care about a performance hit)?

Line number would be a start. But something like this would even be better:

95:    |> Multi.update(:add_something, fn %{required: obj} ->
                                       ^^^^^^^^^^^^^^^^^ arguments didn't match definition

Most Liked

dimitarvp

dimitarvp

I don’t think the stack traces can be improved super quickly but in the meantime you can just insert |> dbg() before the pipe stage that you feel might be failing?

Where Next?

Popular in Questions Top

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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement