(ArithmeticError) bad argument in arithmetic expression
mvrkljan opened this issue · comments
@AlexKovalevych Since upgrade to Elixir 1.5.0 and move to Phoenix 1.3 I'm getting this error when calling Xlsxir.multi_extract/2
. Having a bit of trouble figuring out why, any clue to why this might be happening?
** (exit) an exception was raised:
** (ArithmeticError) bad argument in arithmetic expression
(xlsxir) lib/xlsxir/state_manager.ex:20: anonymous fn/2 in Xlsxir.TableId.assign_id/1
(elixir) lib/agent/server.ex:23: Agent.Server.handle_call/3
(stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:665: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
@mvrkljan do you use the latest version of this library and not my fork which is obsolete atm? tests are passing and everything works fine for me at Elixir 1.5.0
@AlexKovalevych Oh, sorry, it was late and was looking at another issue, should've pinged @jsonkennell :)
Yes, I'm using latest version of this package, {:xlsxir, "~> 1.5"}
. I had a passing test using a simple .xlsx file, but now it fails with this stack trace. I've made sure good path and index is passed into the function. I'll do some more inspecting and prying, was just wondering if this was already encountered perhaps.
@mvrkljan thanks for pointing out this issue. I just upgraded my machine to Elixir 1.5 so I'll try to recreate the error. If you could provide a test .xlsx workbook that is having the issue that would be helpful.
@jsonkennell Sure, this is the file I use in my tests: https://drive.google.com/file/d/0BzFrcoQKgO6ucmxsczRSbUM3UWM/view?usp=sharing
Thanks @mvrkljan. This may be a non issue after the next release as we've completely changed how the state_manager
works. There is still some work to do before this is ready for another release though so I'll see if I can figure out a patch for you in the meantime.
@jsonkennell Thank you! I really appreciate that.
If it helps, I did some debugging using Elixir 1.5.0 break!
and ran my test suite with IEx
, and this is what it got me:
pry(7)> whereami
Location: deps/xlsxir/lib/xlsxir/state_manager.ex:17
15: Assigns an ETS table id to the `TableId` Agent process.
16: """
17: def assign_id(id) do
18: Agent.update(TableId, &(&1 + id))
19: end
pry(8)> Xlsxir.TableId.get()
0
pry(9)> id
#Reference<0.2988041435.285081601.188379>
pry(10)> Xlsxir.TableId.get() + id
** (ArithmeticError) bad argument in arithmetic expression
:erlang.+(0, #Reference<0.2988041435.285081601.188379>)
...
Basically, the whole thing seems to break when the id
ETS reference is added with current state of TableId
on line 18, which is 0
. I'm not sure if something I'm doing causes this, but it seems to be an error not affected by input in higher-level functions that I'm using, which is Xlsxir.multi_extract(report.path, index)
in my case.
I got this as well. Let me know if I can be of help. My backtraces:
** (ArithmeticError) bad argument in arithmetic expression
lib/xlsxir/state_manager.ex:18: anonymous fn/2 in Xlsxir.TableId.assign_id/1
(elixir) lib/agent/server.ex:23: Agent.Server.handle_call/3
(stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:665: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
21:20:32.675 [error] GenServer TableId terminating
** (ArithmeticError) bad argument in arithmetic expression
lib/xlsxir/state_manager.ex:18: anonymous fn/2 in Xlsxir.TableId.assign_id/1
(elixir) lib/agent/server.ex:23: Agent.Server.handle_call/3
(stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:665: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.73.0>): {:update, #Function<0.54024792/1 in Xlsxir.TableId.assign_id/1>}
Still can't reproduce with your file:
iex(1)> Xlsxir.multi_extract("report.xlsx", 0)
{:ok, #Reference<0.385121652.2431778817.147955>}
iex(2)> Xlsxir.multi_extract("report.xlsx")
[ok: #Reference<0.385121652.2431778817.147934>,
ok: #Reference<0.385121652.2431778817.147936>]
iex(3)>
➜ xlsxir git:(master) ✗ elixir -v
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Elixir 1.5.0
DId you try to use the latest xlsxir
from the master
branch?
I tried master
and the error went away, but I got another error:
exit {:noproc, {GenServer, :call, [Xlsxir.StateManager, :new_table, 5000]}}
Hopefully that's helpful.
@cheerfulstoic did you start the OTP application? From the doc:
defp application do
[applications: [:xlsxir]]
end
or if manually:
:ok = Application.ensure_started(:xlsxir)
I haven't been able to reproduce it either in IEx, but I will plug it into a Phoenix app and try again.
I just tested with latest code from master branch and the test that was failing in my app is now passing. I was using 1.5.1 before.
@AlexKovalevych Oh, nice! Sorry I missed that in the docs, but that worked a treat. It's working for me in master
. I tried 1.5.1 after changing the application definition just to see and it's still failing (not surprising). I'll keep on with master
for now. Thanks
Also had a similar issue that seemed to disappear when I switched to the master branch.
Also hit by this, could we get a release as the hex.pm version seems to be broken?
@joshuataylor sure thing, I'll try to get a release out this week. If anyone has time to process some of their workbooks through the master version and let me know if they run into any issues I'd appreciate it. I haven't run into any issues on my end yet.
v1.6 has been published to Hex which should address this issue. Please open a new issue if problems persist.