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

DateTime.from_iso8601 returns unexpected tuple #4260

Closed
brianmay opened this issue Oct 13, 2024 · 6 comments · Fixed by #4293
Closed

DateTime.from_iso8601 returns unexpected tuple #4260

brianmay opened this issue Oct 13, 2024 · 6 comments · Fixed by #4293
Labels
area:teslamate Related to TeslaMate core elixir Pull requests that update Elixir code kind:bug Something isn't working

Comments

@brianmay
Copy link
Collaborator

brianmay commented Oct 13, 2024

date_earliest =
cond do
min_id == 0 ->
DateTime.add(DateTime.utc_now(), -10, :day)
true ->
DateTime.from_iso8601("2003-07-01T00:00:00Z")
end
naive_date_earliest = DateTime.to_naive(date_earliest)

If you look at the logs, there was is scary looking error that isn't generating a test failure:

** (FunctionClauseError) no function clause matching in DateTime.to_naive/1
    (elixir 1.16.2) lib/calendar/datetime.ex:925: DateTime.to_naive({:ok, ~U[2003-07-01 00:00:00Z], 0})
    (teslamate 1.30.2-dev) lib/teslamate/log.ex:185: TeslaMate.Log.get_positions_without_elevation/2
    (teslamate 1.30.2-dev) lib/teslamate/terrain.ex:77: TeslaMate.Terrain.handle_event/4
    (stdlib 5.2.3.2) gen_statem.erl:1397: :gen_statem.loop_state_callback/11
    (stdlib 5.2.3.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Problem is DateTime.from_iso8601 returns a tuple, and could in theory fail. Sigh. Wish Elixir had strong type checking...

In actual practice, this function call probably I think can't fail, the value is constant.

@brianmay
Copy link
Collaborator Author

I suspect (but haven't checked) the reason this didn't cause the tests to fail is because the errors occurred in another process, not the test process.

Which is somewhat unfortunate.

@JakobLichterfeld JakobLichterfeld added the kind:bug Something isn't working label Oct 19, 2024
@swiffer
Copy link
Contributor

swiffer commented Oct 20, 2024

sorry for introducing this issue, not enough elixir experience

@JakobLichterfeld
Copy link
Collaborator

I suspect (but haven't checked) the reason this didn't cause the tests to fail is because the errors occurred in another process, not the test process.

Which is somewhat unfortunate.

Actually, I got a failed test due to this just now: https://github.com/teslamate-org/teslamate/actions/runs/11444547180/job/31839926194?pr=4277#step:6:195

@swiffer
Copy link
Contributor

swiffer commented Oct 21, 2024

no error anymore 🤔is that code change correct ?

https://github.com/teslamate-org/teslamate/actions/runs/11447028841/job/31847674910

@swiffer
Copy link
Contributor

swiffer commented Oct 21, 2024

@JakobLichterfeld - error has already been logged in this run, but test completed successfully

https://github.com/teslamate-org/teslamate/actions/runs/11443404821/job/31836224603

@JakobLichterfeld
Copy link
Collaborator

error has already been logged in this run, but test completed successfully

Yeah, assume the same as Brian:

I suspect (but haven't checked) the reason this didn't cause the tests to fail is because the errors occurred in another process, not the test process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:teslamate Related to TeslaMate core elixir Pull requests that update Elixir code kind:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants