Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor readings dashboard doesn't show when the database is empty #3

Open
jhodapp opened this issue Feb 2, 2022 · 1 comment
Open
Assignees
Labels
bug Something isn't working frontend Any change related to the Ambi frontend

Comments

@jhodapp
Copy link
Member

jhodapp commented Feb 2, 2022

If you stand up a new instance of Ambi, or you truncate the DB tables of all existing data, you'll get an error:

function nil.temperature/0 is undefined

Ambi should handle this error and still display the sensor readings dashboard even when the DB tables are empty.

More details about the error from Phoenix:

Screen Shot 2022-02-02 at 10 47 18

@jhodapp jhodapp added this to Ambi Feb 2, 2022
@jhodapp jhodapp moved this to Todo in Ambi Feb 2, 2022
@jhodapp
Copy link
Member Author

jhodapp commented Feb 2, 2022

It's looking like an issue in lib/ambi.ex in the get_last_row() function. When there aren't any rows, Repo.one() returns nil:

defp get_last_row() do
  Repo.one(from s in Ambi.Reading, order_by: [desc: s.id], limit: 1)
end

We need a guard to detect nil and return an empty reading if there aren't any values in the DB.

Another idea is to use Repo.one!() instead and handle the Ecto.NoResultsError runtime error instead. See the Hexdocs for more information.

@jhodapp jhodapp moved this from Todo to In Progress in Ambi Feb 12, 2022
@jhodapp jhodapp added the bug Something isn't working label Feb 28, 2022
@jhodapp jhodapp added the frontend Any change related to the Ambi frontend label Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working frontend Any change related to the Ambi frontend
Projects
No open projects
Status: In Progress
Development

No branches or pull requests

2 participants