# "(FunctionClauseError) no function clause matching" error

**URL:** <https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366>\
**Category:** Questions\
**Tags:** ecto, mix, phoenix, troubleshooting, learning-elixir, liveview, genserver\
**Created:** [May 3, 2021, 1:23am UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366 "2021-05-03T01:23:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![learning123](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@learning123](https://forum.elixirforum.com/u/learning123)\
**Post date:** [May 3, 2021, 1:23am UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366/1 "2021-05-03T01:23:52Z")

</div>

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

```elixir
** (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`:

```elixir
  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:

```elixir
  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:

```elixir
  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:

```elixir
<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!!

---

<div class="post-metadata">

**Author:** ![derek-zhou](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/derek-zhou/32/19943_2.png) [@derek-zhou](https://forum.elixirforum.com/u/derek-zhou)\
**Post date:** [May 3, 2021, 1:39am UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366/2 "2021-05-03T01:39:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eksperimental](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/eksperimental/32/1401_2.png) [@eksperimental](https://forum.elixirforum.com/u/eksperimental)\
**Post date:** [May 3, 2021, 8:39pm UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366/3 "2021-05-03T20:39:51Z")

</div>

or it is, but the contents do not pattern match

---

<div class="post-metadata">

**Author:** ![learning123](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@learning123](https://forum.elixirforum.com/u/learning123)\
**Post date:** [May 3, 2021, 11:42pm UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366/4 "2021-05-03T23:42:07Z")

</div>

So, I fixed that issue I believe by passing in a struct:

```elixir
  defp get_remaining_time(truck_load) do
    current_truck_load = %TruckLoad{
      pull_point: truck_load.pull_point,
      well: %Well{id: truck_load.well_id}
    }

    driver = TSS.DriverStatuses.list_assignable_drivers_by_truck_load(current_truck_load)
    time_elapsed = Formatters.decorate_time_since_available(driver)

    "#{time_elapsed} (hh:mm)"
  end

```

But now I am getting this error:

**(KeyError) key :pull\_point not found in: ~huge map of `truck_load`’s contents~**

The `truck_load` map has a `pull_point` key, but it’s value is `pull_point: #Ecto.Association.NotLoaded<association :pull_point is not loaded> `

I believe I need to preload `pull_point`, but I shouldn’t do that on the front end, right? I’m not sure how else to access that data though..

Thanks so much for the help, I really really appreciate it!!!

---

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [May 4, 2021, 3:21pm UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366/5 "2021-05-04T15:21:19Z")

</div>

> [@learning123](#):
>
> **(KeyError) key :pull\_point not found in: ~huge map of `truck_load`’s contents~**
> 
> The `truck_load` map has a `pull_point` key

These two statements are not compatible - the error is specifically stating that `truck_load` does NOT have a `:pull_point` key at the beginning of `get_remaining_time`.

Some things to investigate:

- where is the argument to `get_remaining_time` coming from? The code in your initial post suggested it was intended to be a `%TruckLoad{}` struct, but wasn’t.
- as shown in these posts, `list_assignable_drivers_by_truck_load` will return a list of structs (from `Repo.all`) - but `decorate_time_since_available` expects a _single_ driver. Should that be `Repo.one`?

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/astonj/32/15_2.png) [@AstonJ](https://forum.elixirforum.com/u/AstonJ)\
**Post date:** [July 6, 2022, 10:21pm UTC](https://forum.elixirforum.com/t/functionclauseerror-no-function-clause-matching-error/39366/6 "2022-07-06T22:21:15Z")

</div>

2 posts were split to a new topic: [FunctionClauseError on running mix rustler.new (no function clause matching in OptionParser.validate\_swit)](https://forum.elixirforum.com/t/functionclauseerror-on-running-mix-rustler-new-no-function-clause-matching-in-optionparser-validate-swit/48796)
