sheharyarn / memento

Simple + Powerful interface to the Mnesia Distributed Database 💾
http://hexdocs.pm/memento/
MIT License
734 stars 23 forks source link

No function clause when the record does not exist #12

Closed Korbin73 closed 5 years ago

Korbin73 commented 5 years ago

I noticed that if a query fails to return any records, I get the following error: ** (FunctionClauseError) no function clause matching in Memento.Query.coerce_records/1 (memento) lib/memento/query/query.ex:663: Memento.Query.coerce_records(:"$end_of_table")

However calling Mnesia directly, I get the standard message of: {:atomic, []} that I can easily pattern match on.

Korbin73 commented 5 years ago

Nevermind. I looks like I can turn coercion off and handle the end_of_table result myself.

sheharyarn commented 5 years ago

Hey @Korbin73, this might still be a potential bug. Can you please post details about your table structure and the query you executed?

Korbin73 commented 5 years ago

Sure, it's quite simple actually. I have a simple table:

defmodule Request.Record do
  use Memento.Table, attributes: [:url, :response]
end

All I did was do a select that where I knew that the it would not return anything from Mnesia:

Memento.transaction! fn ->
  Memento.Query.select(Request.Record, {:==, url, "gibberish"}, [limit: 1])
end

After looking at the source, I noticed that I could turn off coercion so the coerce_records function isn't called. I was expecting on getting an empty record when it was on instead of an exception, but turning off coercion and matching the result myself is pretty easy.

sheharyarn commented 5 years ago

Yep this was in fact a bug in the code. It should've returned an empty list when no records match. I just published a new release (v0.3.1) to hex.pm with the bugfix.

Thanks for reporting this!