(CompileError) undefined function

Hey guys, I’m new to Elixir, trying to merge my branch into a large code base but the Travis build fails and gives me this error:

1231** (CompileError) test/support/setup_helpers.ex:149: undefined function add_truck_load/3

1232 (elixir 1.11.2) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3

This is line 149 where I call the add_truck_load/3 function:
add_truck_load(attrs, @unload_truck_load_attrs, [:all]

However, I do define this function earlier in the file:

  def add_truck_load(attrs, fields_to_update \\ %{}) do
    |> Enum.into(%{})
    |> add_missing_fields(@dispatch_fields)
    |> add_missing_fields(@driver_fields)
    |> add_missing_fields(@create_truck_load_fields)
    |> add_pending_driver()
    |> create_order()
    |> elem(1)
    |> Repo.preload(:fulfillments)
    |> Map.get(:fulfillments)
    |> List.first()
    |> Map.get(:id)
    |> DriverFulfillments.accept(nil)
    |> elem(1)
    |> Map.get(:truck_load)
    |> TruckLoads.update_truck_load(Enum.into(fields_to_update, %{}), nil)
    |> elem(1)
    |> Map.get(:id)
    |> TruckLoads.get_truck_load!()

Is the issue because of the parameters I’m passing in?

Thanks so much!!

Your error message:

o_O add_truck_load/3

vs the definition: def add_truck_load(attrs, fields_to_update \\ %{})

I don’t see the issue here :sweat_smile: The function add_truck_load should take 3 parameters, and in the function definition it takes 2 and an optional third, correct?

has arity 2, but you are calling it with 3 arguments;

thus the error says:

1 Like

doesn’t the \ %{} part in the function’s parameters mean that it takes an optional 3rd argument?

nope, it states that the second param is optional with default value equal to %{}


ahh ok :sweat_smile: thank you!!!