Skip to content

Commit c280ff2

Browse files
author
Andrew Mayorov
authored
Merge pull request #16 from rbkmoney/ED-266/fix/bad-fun-name
Error out properly when service missing some function
2 parents 846a081 + ddb97f8 commit c280ff2

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/thrift_processor_codec.erl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,30 @@ read_function_call(Buffer, Codec, Service) ->
4141
type = Type,
4242
seqid = SeqId},
4343
Buffer1} when Type =:= ?tMessageType_CALL; Type =:= ?tMessageType_ONEWAY ->
44-
try erlang:binary_to_existing_atom(FName, latin1) of
45-
Function -> read_function_params(Buffer1, Codec, Service, Function, Type, SeqId)
46-
catch
47-
error:badarg -> {error, {bad_function_name, FName}}
48-
end;
44+
read_function_call(Buffer1, Codec, Service, FName, Type, SeqId);
4945
{error, _} = Error ->
5046
Error
5147
end.
5248

53-
read_function_params(Buffer, Codec, Service, Function, IType, SeqId) ->
54-
InParams = get_function_info(Service, Function, params_type),
49+
read_function_call(Buffer, Codec, Service, FName, IType, SeqId) ->
50+
case get_function_params_info(Service, FName) of
51+
{ok, Function, InParams} ->
52+
read_function_params(Buffer, Codec, Function, InParams, IType, SeqId);
53+
Error ->
54+
Error
55+
end.
56+
57+
get_function_params_info(Service, FName) ->
58+
try
59+
Function = erlang:binary_to_existing_atom(FName, latin1),
60+
InParams = get_function_info(Service, Function, params_type),
61+
{ok, Function, InParams}
62+
catch
63+
error:badarg ->
64+
{error, {bad_function_name, FName}}
65+
end.
66+
67+
read_function_params(Buffer, Codec, Function, InParams, IType, SeqId) ->
5568
Type = case IType of
5669
?tMessageType_CALL -> call;
5770
?tMessageType_ONEWAY -> oneway

test/generic_codec_test.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ error_test_() ->
7171
)
7272
].
7373

74+
bad_function_name_test_() ->
75+
Service1 = {thrift_test_thrift, 'ThriftTest'},
76+
Function1 = 'testString',
77+
Args1 = {<<"blarg">>},
78+
Service2 = {thrift_test_thrift, 'SecondService'},
79+
[
80+
?_assertEqual(
81+
{error, {bad_function_name, <<"testString">>}},
82+
begin
83+
B0 = ?CODEC:new(),
84+
{ok, B1} = thrift_client_codec:write_function_call(B0, ?CODEC, Service1, Function1, Args1, ?SEQID),
85+
thrift_processor_codec:read_function_call(B1, ?CODEC, Service2)
86+
end
87+
)
88+
].
89+
7490
roundtrip(Service, Function, Args, Result) ->
7591
roundtrip(Service, call, Function, Args, Result).
7692

0 commit comments

Comments
 (0)