Ejabberd module do not compile after update - erlang

I, i have updated ejabberd from 16.01 to 16.03, i have a problem with my module, before update this line of code
Type = Packet#xmlel.attrs,
io:format("types:~p~n" , [Type]),
%Get raw data of message
Message = xml:element_to_binary(Packet).
works fine, now after update produce this:
types:[{<<"type">>,<<"chat">>}, {<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}]
16:57:13.393 [error]
{undef,
[{xml,element_to_binary,
[{xmlel,<<"message">>,
[{<<"type">>,<<"chat">>},
{<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}],
[{xmlel,<<"composing">>,
[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],
[]}]}], []},
{ejabberd_hooks,safe_apply,3,
[{file,"src/ejabberd_hooks.erl"},{line,382}]},
{ejabberd_hooks,run1,3,
[{file,"src/ejabberd_hooks.erl"},{line,329}]},
{ejabberd_sm,route,3,
[{file,"src/ejabberd_sm.erl"},{line,114}]},
{ejabberd_local,route,3,
[{file,"src/ejabberd_local.erl"},{line,112}]},
{ejabberd_router,route,3,
[{file,"src/ejabberd_router.erl"},{line,77}]},
{ejabberd_c2s,check_privacy_route,5,
[{file,"src/ejabberd_c2s.erl"},{line,2110}]},
{ejabberd_c2s,session_established2,2,
[{file,"src/ejabberd_c2s.erl"},{line,1271}]}]}
running hook:
{offline_message_hook,
[{jid,<<"121">>,<<"node0.frind.it">>,
<<"97395769126380428951460048231139020">>,<<"121">>,
<<"node0.frind.it">>,
<<"97395769126380428951460048231139020">>},
{jid,<<"154">>,<<"node0.frind.it">>,<<>>,<<"154">>,
<<"node0.frind.it">>,<<>>},
{xmlel,<<"message">>,
[{<<"type">>,<<"chat">>},
{<<"to">>,<<"154#node0.frind.it">>},
{<<"from">>,<<"121#node0.frind.it">>}],
[{xmlel,<<"composing">>,
[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]}]}
]}
Anyone can help me?

Latest ejabberd move to library fast_xml. Use fxml module instead of xml.

Related

YAWs embedded with appmod not working for me

Alright, what am I doing wrong here. I'm trying the simple example of embedded YAWs from http://yaws.hyber.org/embed.yaws but with an appmod. I've added the my_app.erl file and compiled it. It works if not in embedded YAWs so I think it is specific to embedded.
-module(ybed).
-compile(export_all).
start() ->
{ok, spawn(?MODULE, run, [])}.
run() ->
Id = "embedded",
GconfList = [{ebin_dir, ["/Users/someuser/yawsembedded/ebin"]}],
Docroot = "/Users/someuser/yawstest",
SconfList = [{port, 8888},
{listen, {0,0,0,0}},
{docroot, Docroot},
{appmods, [{"/", my_app}]}
],
{ok, SCList, GC, ChildSpecs} =
yaws_api:embedded_start_conf(Docroot, SconfList, GconfList),
[supervisor:start_child(ybed_sup, Ch) || Ch <- ChildSpecs],
yaws_api:setconf(GC, SCList),
{ok, self()}.
Getting this Error:
ERROR erlang code threw an uncaught exception:
File: appmod:0
Class: error
Exception: undef
Req: {http_request,'GET',{abs_path,"/demo"},{1,1}}
Stack: [{my_app,out,
[{arg,#Port<0.2721>,
{{127,0,0,1},63720},
{headers,"keep-alive",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"0.0.0.0:8888",undefined,undefined,undefined,undefined,
undefined,undefined,undefined,
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0",
undefined,[],undefined,undefined,undefined,undefined,
undefined,undefined,undefined,undefined,
[{http_header,0,"Dnt",undefined,"1"},
{http_header,10,'Accept-Encoding',undefined,
"gzip, deflate"},
{http_header,11,'Accept-Language',undefined,"null"}]},
{http_request,'GET',{abs_path,"/demo"},{1,1}},
{http_request,'GET',{abs_path,"/demo"},{1,1}},
undefined,"/demo",undefined,undefined,
"/Users/someuser/yawstest","/",
"/Users/someuser/yawstest/demo",undefined,undefined,
<0.63.0>,[],"/","/",undefined}],
[]},
{yaws_server,deliver_dyn_part,8,
[{file,"yaws_server.erl"},{line,2818}]},
{yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1232}]},
{yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1068}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]
The stack trace shows that your my_app:out/1 function is getting called, but you're getting an undef exception. This is occurring because the runtime can't find the my_app:out/1 function, which means either it can't find the module or the module exists but does not export an out/1 function. For example, I was able to duplicate the error using the example code by not providing a my_app module.
First, make sure your my_app.erl file exports an out/1 function. Here's a trivial one that just returns a 405 error for all requests:
-module(my_app).
-export([out/1]).
out(_Arg) ->
{status, 405}.
Compile your my_app.erl file and put the compiled my_app.beam file either in a load path already known to the Erlang runtime, or in a directory you add to the load path. In your code it appears you're trying the latter approach, since you're specifically adding an ebin_dir with this Yaws global configuration directive:
GconfList = [{ebin_dir, ["/Users/someuser/yawsembedded/ebin"]}],
You need to verify that the /Users/someuser/yawsembedded/ebin directory exists, and that the compiled my_app.beam file is located there.

erlang rfc4627 decode error

I am trying to decode json data in yaws, getting an error which is not clear to identify the issue. The Json data is
{
"airport": [
{"airport": "MAA"},
{"city": "Chennai"},
{"country": "India"},
{"name": "Anna International Airport"}
]
}
The command i am using is
{ok, Json, _} = rfc4627:decode(Arg#arg.clidata).
The error is
Exception: undef Req:
{http_request,'POST',{abs_path,"/sample/rest.yaws"},{1,1}} Stack:
[{rfc4627,decode,
[<<"{\n \"airport\": [\n {\"airport\": \"MAA\"},\n {\"city\": \"Chennai\"},\n {\"country\":
\"India\"},\n {\"name\": \"Anna International Airport\"}\n
]\n}">>],
[]},
You're getting an undef exception, indicating that you're calling an undefined function. The error shows the stack, and at the top of the stack is the rfc4627:decode/1 function; that's the one that's undefined.
My guess is that your load path does not include the directory where you've stored the compiled rfc4627 module. You can add that directory to the Yaws load path by modifying your yaws.conf file and adding something like the following to the global config section (near the top):
ebin_dir = /path/to/where/rfc4627/is/stored
Note that you're allowed to have multiple ebin_dir settings; each is added to the load path.

What causes a "not mocked" error when using meck (Erlang)?

I'm a meck (and Erlang) newbie and I'm struggling a bit with meck. I'm getting the following error:
=ERROR REPORT==== 27-Jan-2014::16:20:05 ===
Error in process <0.1825.0> with exit value: {{not_mocked,substatsDb},
[{meck_proc,gen_server,3,[{file,"src/meck_proc.erl"},{line,443}]},{meck_code_gen,exec,4,
[{file,"src/meck_code_gen.erl"},{line,147}]},{substats,loop,1,
[{file,"/Users/uyounri/gitsandbox/subpub/src/su...
At the beginning of my test I declare the module to be mocked:
meck:new(substats)
At the very end of my test the last thing I do is to unload the module that was mocked mocked:
meck:unload(substats)
The mocking seems to be working as expected until towards the end of the test when the above error is produced.
Thanks,
Rich
EDIT
Adding 2 ?debugFmt() lines seems to have fixed the problem; at least I no longer get the error. Here's the complete function that was modified:
stop(_) ->
meck:expect(substatsDb, stop, 1, fun(dbconn) -> ok end),
substats:stop(),
%% Note: this and the next ?debugFmt() calls prevent a meck
%% exit error. They both have to be present to prevent the error
?debugFmt("stop:~n", []),
meck:unload(substatsDb),
?debugFmt("stop: exit~n", []).
Have you tried adding the option passthrough when mocking the module?
meck:new(substatsDb, [passthrough])
Also, you are using the module "substatsDb" in the meck:expect call, but doing the meck:new for another module (substats), you should be doing everything for the same modules (new, expect, and unload)
hope it helps!

erlang_protobuffs doesn't decode as expected for messages with repeated field

I am working on a project that uses google proto buffers for internal data exchanges. It works fine as advertised, however it doesn't works as expected for messages with repeated fields in them. Here is an example:
Sample test.proto file:
message Test {
optional string t = 1;
}
message Tests {
repeated Test testsList = 1;
}
Generate erlang code:
1> protobuffs_compile:scan_file("test.proto").
=INFO REPORT==== 14-Sep-2012::16:38:25 ===
Writing header file to "test_pb.hrl"
=INFO REPORT==== 14-Sep-2012::16:38:25 ===
Writing beam file to "test_pb.beam"
ok
Generated test_pb.hrl:
-ifndef(TEST_PB_H).
-define(TEST_PB_H, true).
-record(test, {
t
}).
-endif.
-ifndef(TESTS_PB_H).
-define(TESTS_PB_H, true).
-record(tests, {
testslist = []
}).
-endif.
Encode:
5> test_pb:encode_tests({tests, [{test, <<"t">>}]}).
<<10,3,10,1,116>>
Decode:
6> test_pb:decode_tests(<<10,3,10,1,116>>).
{[{test,"t"}],undefined}
As in the above example, decoding doesn't give back the expected record tuple:
{tests, [{test, <<"t">>}]}
Has someone faced a similar issue before? Where am I missing the trick?
Any pointers and help will be greatly appreciated.
For versioning info, deps line from my rebar.config:
{protobuffs, "0.7.0", {git, "git://github.com/basho/erlang_protobuffs.git", {tag, "0.7.0"}}}
Just for an update.
0.7.0, 0.6.0 and HEAD were all giving me the same problem as described above.
After discussion on #riak IRC, I realized we need to use stable release marked by this commit hash: e0f5f6ea4c3dcb4e7b824496d2b48333fbd5a8c8 which solves the above issue.

creating Keyspace

I am trying to access cassandra from erlang, as a test I am trying to create a new keyspace. I do it as follows:
1> rr(cassandra_thrift).
[authenticationException,authenticationRequest,
authorizationException,cfDef,column,columnDef,
columnOrSuperColumn,columnParent,columnPath,counterColumn,
counterSuperColumn,cqlMetadata,cqlResult,cqlRow,deletion,
endpointDetails,indexClause,indexExpression,
invalidRequestException,keyCount,keyRange,keySlice,ksDef,
mutation,notFoundException,schemaDisagreementException,
slicePredicate,sliceRange,superColumn|...]
2> {ok,C1}=thrift_client_util:new("127.0.0.1",9160,thrift_cassandra,[]).
{ok,{tclient,thrift_cassandra,
{protocol,thrift_binary_protocol,
{binary_protocol,
{transport,thrift_buffered_transport,
{buffered_transport,
{transport,thrift_socket_transport,
{data,#Port<0.593>,infinity}},
[]}},
true,true}},
0}}
3> Reply1=thrift_client:call(C1,set_keyspace,["Test_KS"]).
** exception exit: undef
in function thrift_cassandra:function_info/2
called as thrift_cassandra:function_info(set_keyspace,params_type)
in call from thrift_client:send_function_call/3 (thrift_client.erl, line 70)
in call from thrift_client:call/3 (thrift_client.erl, line 40)
Am I doing something wrong, or does my erlang not have access to the cassandra functions? How can I fix it?
I would use https://github.com/ostinelli/erlcassa over raw Thrift from Erlang.

Resources