ArneVogel / listudy

Listudy - chess training server
https://listudy.org
GNU Affero General Public License v3.0
290 stars 44 forks source link

(ArithmeticError) bad argument in arithmetic expression #86

Open Yky opened 3 years ago

Yky commented 3 years ago

I updated to the latest sources and ran mix setup. Then I get the following error:

Any ideas what could be causing this or how to fix it?

Listudy no longer works locally due to this error.

I already triedmix run priv/repo/seeds.exs as recommended in #39

** (exit) an exception was raised:
    ** (ArithmeticError) bad argument in arithmetic expression
        :erlang.rem(2827954, 0)
        (listudy 0.1.0) lib/listudy_web/controllers/tactic_controller.ex:205: ListudyWeb.TacticController.daily_id/0
        (listudy 0.1.0) lib/listudy_web/controllers/tactic_controller.ex:198: ListudyWeb.TacticController.daily_tactic/0
        (listudy 0.1.0) lib/listudy_web/controllers/page_controller.ex:22: ListudyWeb.PageController.index/2
        (listudy 0.1.0) lib/listudy_web/controllers/page_controller.ex:1: ListudyWeb.PageController.action/2
        (listudy 0.1.0) lib/listudy_web/controllers/page_controller.ex:1: ListudyWeb.PageController.phoenix_controller_pipeline/2
        (phoenix 1.5.8) lib/phoenix/router.ex:352: Phoenix.Router.__call__/2
        (listudy 0.1.0) lib/listudy_web/endpoint.ex:1: ListudyWeb.Endpoint.plug_builder_call/2
        (listudy 0.1.0) lib/plug/debugger.ex:136: ListudyWeb.Endpoint."call (overridable 3)"/2
        (listudy 0.1.0) lib/listudy_web/endpoint.ex:1: ListudyWeb.Endpoint.call/2
        (phoenix 1.5.8) lib/phoenix/endpoint/cowboy2_handler.ex:65: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.8.0) /home/user/listudy/listudy/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.8.0) /home/user/listudy/listudy/deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
        (cowboy 2.8.0) /home/user/listudy/listudy/deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
        (stdlib 3.14.2.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
ArneVogel commented 3 years ago

Can you run mix ecto.drop and then post the output of mix setup? mix ecto.drop will delete the listudy_dev database so don't run this if you have anything worth keeping in there before backing that up.

Yky commented 3 years ago

Here is the log of mix setup: https://gist.github.com/Yky/7f4afd5bf7f95c6c7459e8fd3e31b416

ArneVogel commented 3 years ago

That looks like how it should look like.

Can you visit http://localhost:4000/en/tactics/1 ? Does that page work for you?

Also can you post what Erlang and Elixir version you are using? Both can be seen with elixir --version

Yky commented 3 years ago

Yes, the page works for me after removing the old database.

Erlang/OTP 23 [erts-11.2.2.4] Elixir 1.11.3

However, http://localhost:4000/en/studies/mystudy does not work. I imported a pgn for black and it says:

Starting training.

At first the arrows will show you which moves are in this study. Once you have played these moves twice, the arrows are no longer shown.

However, the board stays in the original position and no first move is played for white nor are any arrows shown. Not sure if this is related to the original issue or not.

ArneVogel commented 3 years ago

However, the board stays in the original position and no first move is played for white nor are any arrows shown. Not sure if this is related to the original issue or not.

This normally occurs with faulty pgns. Can you try importing https://lichess.org/study/sHdoiJzk and see if that works.

Back to the original issue: I have it working on Erlang 23 and Elixir 1.11.2 so that should be no issue. On what pages does the error occur?

Yky commented 3 years ago

This normally occurs with faulty pgns. Can you try importing https://lichess.org/study/sHdoiJzk and see if that works.

I tried this and for example if I select the chapter 🔥⚔️The Art of Attack ⚔️🔥: 🗡️The Ng4 /Ng5 sacrifices, the arrow is shown to play e4. After I play e4 nothing happens and the training is stuck.

As stated above, the other error no longer occurs after deleting the database as you recommended above. It seems like something broke when updating listudy and/or some dependencies that caused this ArithmeticError.

ArneVogel commented 3 years ago

Did you run npm install --prefix assets?

As stated above, the other error no longer occurs after deleting the database as you recommended above

Nice

Yky commented 3 years ago

Did you run npm install --prefix assets?

Yes, i just ran it again and still don't get any reaction to 1.e4

ArneVogel commented 3 years ago

Are there any errors in the browser console?

Yky commented 3 years ago

Are there any errors in the browser console?

No, I don't see any errors there. The same problem exists with tactics: If the wrong move is found it displays the red message: Wrong move, try again. However, if the correct move is played, the tactic does not continue.

I.e. the solution states Bb5+ d3 Bxd3+ Kg1 Bf2# I play BB5 and then nothing happens.

In the console I see the following error: ** (ArgumentError) cannot convert nil to param (phoenix 1.5.8) lib/phoenix/param.ex:67: Phoenix.Param.Atom.to_param/1 (listudy 0.1.0) ListudyWeb.Router.Helpers.tactics_path/5 (listudy 0.1.0) lib/listudy_web/live/tactics_live.ex:28: ListudyWeb.TacticsLive.handle_event/3 (phoenix_live_view 0.15.4) lib/phoenix_live_view/channel.ex:338: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3 (telemetry 0.4.2) /home/user/listudy/listudy/deps/telemetry/src/telemetry.erl:262: :telemetry.span/3 (phoenix_live_view 0.15.4) lib/phoenix_live_view/channel.ex:203: Phoenix.LiveView.Channel.handle_info/2 (stdlib 3.14.2.2) gen_server.erl:689: :gen_server.try_dispatch/4 (stdlib 3.14.2.2) gen_server.erl:765: :gen_server.handle_msg/6 (stdlib 3.14.2.2) proc_lib.erl:236: :proc_lib.wake_up/3 Last message: %Phoenix.Socket.Message{event: "event", join_ref: "13", payload: %{"event" => "next", "type" => "click", "value" => %{"value" => ""}}, ref: "16", topic: "lv:phx-Fpr_Isz8Er9z3QFi"} State: %{components: {%{}, %{}, 1}, join_ref: "13", serializer: Phoenix.Socket.V2.JSONSerializer, socket: #Phoenix.LiveView.Socket<assigns: %{canonical: "/en/tactics/1", flash: %{}, live_action: nil, locale: "en", noindex: true, tactic: %Listudy.Tactics.Tactic{__meta__: #Ecto.Schema.Metadata<:loaded, "tactics">, ...}}, changed: %{}, endpoint: ListudyWeb.Endpoint, id: "phx-Fpr_Isz8Er9z3QFi", parent_pid: nil, root_pid: #PID<0.902.0>, router: ListudyWeb.Router, view: ListudyWeb.TacticsLive, ...>, topic: "lv:phx-Fpr_Isz8Er9z3QFi", transport_pid: #PID<0.890.0>, upload_names: %{}, upload_pids: %{}}

ArneVogel commented 3 years ago

I cannot reproduce the problem you are describing. Can you try the steps from the readme from beginning?

Yky commented 3 years ago

I installed it from scratch now and it works now, so I think this can be closed. It was a problem migrating from an older version of listudy to a newer one, but I don't think it is worth analyzing this further. Thanks a lot for your help!