0

The Chicago Boss tutorial

http://www.chicagoboss.org/tutorial.pdf

gives an example of a BossRecord automatically being converted to JSON in a controller response to a GET like this:

pull('GET', [LastTimestamp]) ->
    {ok, Timestamp, Greetings} = boss_mq:pull("new-greetings", list_to_integer(LastTimestamp)),
    {json, [{timestamp, Timestamp}, {greetings, Greetings}]}.

However, this code doesn't work. boss_json will not convert "Greetings" record it gets from the boss_mq:pull, and gives me an unhandled error. I'm having a hard time figuring out what it wants.

16:50:45.634 [error] Unhandled Error: error:function_clause. 
Stacktrace: [{boss_json,json_data1,[[{greeting,"greeting-77","zz"}],[],[]],
[{file,"src/boss/boss_json.erl"},{line,31}]},
{boss_json,json_data1,3,[{file,"src/boss/boss_json.erl"},{line,42}]},
{boss_json,encode,2,[{file,"src/boss/boss_json.erl"},{line,16}]},
{boss_web_controller_render,process_action_result,4,[{file,"src/boss/boss_web_controller_render.erl"},{line,171}]},
{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,337}]},
{boss_web_controller_handle_request,process_dynamic_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,242}]},
{boss_web_controller_handle_request,process_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,228}]},
{boss_web_controller_handle_request,set_timer,7,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,148}]}]

16:50:45.636 [info] POST /greeting/create [cbmonitor] 302 0ms

Any ideas why the tutorial example (written several years ago) no longer works in the current version of Chicago Boss?

Thrill Science
  • 408
  • 4
  • 14

1 Answers1

1

This isn't actually an answer, but it is too long for comment. I run the example code from chicagoboss_tutorial and it works for me. You might try cloning this repository and checking out, what differs.

I also run dbg during execution.

dbg:tracer().
dbg:tpl(boss_json, '_', []).
dbg:p(all, c).

and it gave me following output:

(<0.195.0>) call boss_json:encode([{timestamp,1417745752505174},{greetings,
[{greeting,"greeting-4","asdf"}]}],["greeting"])
(<0.195.0>) call boss_json:json_data1([{timestamp,1417745752505174},{greetings,[{greeting,"greeting-4","asdf"}]}],["greeting"],[])
(<0.195.0>) call boss_json:json_data1([{greetings,[{greeting,"greeting-4","asdf"}]}],["greeting"],[{timestamp,1417745752505174}])
(<0.195.0>) call boss_json:json_data1([],["greeting"],[{greetings,[{struct,[{id,<<"greeting-4">>},{greeting_text,<<"asdf">>}]}]},

Second argument of boss_json:encode/2 and boss_json:json_data1 is ModelList and for some reason, you have empty model list. As I said before - try to compare your code with the code from repository.

tkowal
  • 9,129
  • 1
  • 27
  • 51
  • Thanks! I was copy/pasting from the PDF. There may have been some changes that are reflected in the repo. For one thing, it looks like it's passing an extra argument with the name of the BossRecord type where I'm passing in an empty list.... – Thrill Science Dec 05 '14 at 02:42
  • Though the repository has the "after_create" commented out which can't possibly work.... – Thrill Science Dec 05 '14 at 02:54
  • I uncommented that part. I think It was the only change, I made. – tkowal Dec 05 '14 at 08:34
  • Thanks. I'm just going to move on with the tutorial because these hooks / triggers aren't the "right" way to do it anyway. There's something funny with R17 or one of the libraries in my build. – Thrill Science Dec 05 '14 at 19:45
  • 1
    That is the problem! I was using R16B02. I tried to use R17 now and also got error, but different than yours. There was also massive amount of warning about using deprecated things during compilation. I think, that it is better to stick with R16B02 until CB team fixes those things. – tkowal Dec 05 '14 at 20:20
  • Well, now I'm stuck. I need R17 for other things. Guess I need to find another web framework. Thanks for your help. – Thrill Science Dec 05 '14 at 20:22
  • Hey! Good news, tkowal! I downloaded the latest R17 sources and it works in that. So whatever it was has been fixed. Phew! – Thrill Science Dec 05 '14 at 21:28