Exception error using nitrogen qdate:add_days/2

Working through “Build it with Nitrogen” and I get to listing 10.26 trying to use qdate functions. I am running on WSL2/Ubunto 20.04 with Erlang 25 and nitrogent 2.4.0. Get the following when trying to execute qdate:add_days/2 per the book:

(nnote@> DateTime = calendar:universal_time().
(nnote@> EarlyDate = qdate:add_days(-7,DateTime).
** exception error: bad argument
     in function  ets:match_object/2
        called as ets:match_object(qdate_srv,'_')
        *** argument 1: the table identifier does not refer to an existing ETS table
     in call from ets:tab2list/1 (ets.erl, line 771)
     in call from qdate_srv:get_all_env/1 (src/qdate_srv.erl, line 155)
     in call from qdate:try_registered_parsers/1 (src/qdate.erl, line 1148)
     in call from qdate:to_date/3 (src/qdate.erl, line 313)
     in call from qdate:add_days/2 (src/qdate.erl, line 668)
(nnote@> erlang:system_info(otp_release).

If I use the windows installation of nitrogen and just start the demo project everything appears to work fine:

(nitrogen@> DateTime = calendar:universal_time().
(nitrogen@> EarlyDate = qdate:add_days(-7,DateTime).
(nitrogen@> erlang:system_info(otp_release).

Any ideas on why qdate is not working under Linux? Thanks in advance for any help provided. I’ve been trying to solve this for days! Reinstalled everything, re-did all work from the book. All to end up stuck at the same place.

1 Like


This is likely related to a change in qdate in the past few years. Make sure that qdate is actually started: qdate:start().

If you edit the file site/src/nitrogen_sup.erl in your generated project, you can also insert qdate:start(), in the init/1 function as well.

I’ll have to update the output from the generated 2.4 nitrogen to adapt to that change to qdate (I thought I had done that, but maybe not) - most of my time in nitrogen lately has been in nitrogen 3.

My apologies. Give that a shot and let me know if that helps.

1 Like

Oddly enough, I was just poking around the source for qdate this morning, after I posted my question, and realized that there was now a server that needed to be started. I was looking for where to put the call to start it.

Thank you for your quick reply as it not only gave me the answer but verified I was on the right path to solving it.

Should have examined the qdate source more thoroughly last week when this started and/or posted here sooner.

FWIW, very happy with what I’m seeing in Nitrogen as it looks like it will enable me to build the front-end for my application much easier than trying to use wxerlang which I’ve played with a bit but that has a pretty steep learning curve for someone both newer to erlang and even less experience with wx.

Sincerely yours,
Alan Gingras

1 Like

Awesome! So glad to hear it! Don’t sweat it about the whole “having to look up in the source code.” That’s just legitimately a bug. But I’ve pushed the fix to the nitrogen master branch so others shouldn’t be burned by it.

Thank you for your feedback on Nitrogen, and good luck with building your application!

1 Like

If you don’t mind, I’d like to ask another question. Now working on Chapter 11 Simple Login and struggling with building erlpass. If I download erlpass it builds with rebar3 fine. But when I try and build using make under nnote, it fails while building bcrypt.

Compiling /home/agingras/projects/nnote/lib/bcrypt/c_src/bcrypt_port.c
/home/agingras/projects/nnote/lib/bcrypt/c_src/bcrypt_port.c:20:10: fatal error: erl_interface.h: No such file or directory
20 | #include <erl_interface.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
ERROR: compile failed while processing /home/agingras/projects/nnote/lib/bcrypt: rebar_abort

Nothing I’ve tried has worked and I think this has to do with the use of rebar and the version of erlang (25). I’ve found issues in GIT that say this is a problem and that it was fixed but have been unable to figure out what that fix was!

Any guidance you could provide would be much appreciated.

Sincerely yours,
Alan Gingras

1 Like

Hi @agingras, you’re right. I did a little experimenting here for you, since you’re right, it’s crashing on Erlang 25 (Oh man, I gotta release Nitrogen 3 like now!)

Okay, here’s the fix for now:

For the erlpass dependency, use this:

{erlpass, {git, "https://github.com/choptastic/erlpass", {branch,rebar2}}}

That should work.

Going forward, with the future projects, it’s worth trying to use the rebar3 branch of nitrogen. In your nitrogen directory:

git checkout rebar3

Most of the book should work as expected with that. For example:

make slims_cowboy PROJECT=myproject

Will roughly do the same. The main difference, for development, is that from your new myproject directory, you can just do:

make run_dev

To launch a development environment. which is just a shorter version of:

rebar3 shell --eval "sync:go()."
1 Like

Thank you for all your help. I’ll try the immediate fix, then move on to rebar3 version of nitrogen. Very grateful for all your help as I learn Nitrogen and work through the book. Teaching me a good bit about Erlang as well! This is working well as yet another tutorial on the language. Which I always welcome as I am still new to it and have yet to convince my employer that it would be a good fit for much of what we do. But that is a battle I’ve not given up on yet - but they’ve got lots invested in C/C++ and it’s hard to change the course of a battleship! But it can be done.