learning123

learning123

"(FunctionClauseError) no function clause matching" error

Hey all, I’m new to elixir and getting the following error:

** (FunctionClauseError) no function clause matching in TSS.DriverStatuses.list_assignable_drivers_by_truck_load/1

So in my module, I define a get_remaining_time function that takes a truck_load:

  defp get_remaining_time(truck_load) do
    time_since_available = DriverStatuses.list_assignable_drivers_by_truck_load(truck_load)
    Formatters.decorate_time_since_available(time_since_available)
  end

This function uses the list_assignable_drivers_by_truck_load in the DriverStatuses module, which looks like this:

  def list_assignable_drivers_by_truck_load(%TruckLoad{
        well: %{id: well_id},
        pull_point: pull_point
      }) do
    base_assignable_drivers_query()
    |> apply_default_select(pull_point.point)
    |> filter({:well_id, well_id})
    |> sort({:distance_in_meters, :asc}, %{"pull_point_id" => pull_point.id})
    |> preload(driver: [:trailer_type, driver_contract: [:carrier]])
    |> Repo.all()
  end

and then formats it using the decorate_time_since_available function in the Formatters module, which looks like this:

  def decorate_time_since_available(%{driver_status: %{last_available_at: last_available_at}})
      when not is_nil(last_available_at),
      do:
        humanize_time(DateTime.diff(DateTime.utc_now(), last_available_at), :seconds, :minutes) <>
          " (hh:mm)"

  def decorate_time_since_available(_), do: "N/A"

Finally, I am calling the function like so:

<CardInfo label="Time Since Available" title={{ get_remaining_time(@truck_load) }} small />

I think I’m not pattern matching correctly, but nothing I’ve tried is working. How can I fix this?
Thanks so much!!

Most Liked

derek-zhou

derek-zhou

So your @truck_load is not a %TruckLoad(...} then. the error message after the ** (FunctionClausError)... line should give you more clue

Last Post!

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New