Fix errors filtering from events (#12)

Port changes from rbkmoney/cds#94
And update woody to fix errors handing in woody
This commit is contained in:
Andrey Fadeev 2019-08-27 14:33:36 +03:00 committed by GitHub
parent 866073c3bb
commit 83fbfef475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 28 deletions

View File

@ -19,35 +19,23 @@
Meta :: woody_event_handler:event_meta(),
Opts :: woody:options().
handle_event(?EV_INTERNAL_ERROR, RpcID, RawMeta, Opts) ->
RawMetaWithoutReason = RawMeta#{reason => <<"***">>},
scoper_woody_event_handler:handle_event(?EV_INTERNAL_ERROR, RpcID, RawMetaWithoutReason, Opts);
handle_event(Event, RpcID, RawMeta, Opts) ->
FilteredMeta = filter_meta(RawMeta),
scoper_woody_event_handler:handle_event(Event, RpcID, FilteredMeta, Opts).
filter_meta(RawMeta) ->
case RawMeta of
#{result := Result} ->
RawMeta#{result => filter_result(Result)};
#{args := Args} ->
RawMeta#{args => filter_args(Args)};
_ ->
RawMeta
end.
%% Internals
filter_result({ok, Result}) -> {ok, filter(Result)};
filter_result({system, SystemError}) -> {system, filter(SystemError)};
filter_result({exception, Exception}) -> {exception, filter(Exception)};
filter_result(Result) -> filter(Result).
filter_meta(RawMeta0) ->
maps:map(fun do_filter_meta/2, RawMeta0).
filter_args(Args) -> filter(Args).
filter(L) when is_list(L) -> [filter(E) || E <- L];
filter(M) when is_map(M) -> maps:map(fun (_K, V) -> filter(V) end, M);
filter({internal, Error, Details} = V) when is_atom(Error) and is_binary(Details) -> V;
filter({external, Error, Details} = V) when is_atom(Error) and is_binary(Details) -> V;
do_filter_meta(result, Result) ->
filter(Result);
do_filter_meta(reason, Error) ->
filter(Error);
do_filter_meta(args, Args) ->
filter(Args);
do_filter_meta(_Key, Value) ->
Value.
filter(#cds_EncryptedMasterKeyShare{} = EncryptedMasterKeyShare) ->
EncryptedMasterKeyShare#cds_EncryptedMasterKeyShare{encrypted_share = <<"***">>};
@ -58,8 +46,6 @@ filter(#cds_Keyring{keys = Keys} = Keyring) ->
filter(#cds_Key{} = Key) ->
Key#cds_Key{data = <<"***">>};
filter(V) when is_integer(V) -> V;
filter(ok) -> ok;
filter({success, #cds_Success{}} = V) -> V;
filter({more_keys_needed, D} = V) when is_integer(D) -> V;
filter(#cds_KeyringState{} = V) -> V;
@ -71,4 +57,28 @@ filter(#cds_InvalidActivity{} = V) -> V;
filter(#cds_InvalidKeyringMeta{} = V) -> V;
filter(#cds_InvalidArguments{} = V) -> V;
filter(#cds_VerificationFailed{} = V) -> V;
filter(#cds_OperationAborted{} = V) -> V.
filter(#cds_OperationAborted{} = V) -> V;
%% woody errors
filter({internal, Error, Details} = V) when is_atom(Error) and is_binary(Details) -> V;
filter({external, Error, Details} = V) when is_atom(Error) and is_binary(Details) -> V;
%% Known woody error reasons
filter(<<"Deadline reached">> = V) -> V;
filter(<<"partial response">> = V) -> V;
filter(<<"thrift protocol read failed">> = V) -> V;
%% common
filter(V) when is_atom(V) -> V;
filter(V) when is_number(V) -> V;
filter(L) when is_list(L) -> [filter(E) || E <- L];
filter(T) when is_tuple(T) -> list_to_tuple(filter(tuple_to_list(T)));
filter(M) when is_map(M) -> genlib_map:truemap(fun (K, V) -> {filter(K), filter(V)} end, M);
filter(B) when is_bitstring(B) -> <<"***">>;
filter(P) when is_pid(P) -> P;
filter(P) when is_port(P) -> P;
filter(F) when is_function(F) -> F;
filter(R) when is_reference(R) -> R;
%% fallback
filter(_V) -> <<"*filtered*">>.

View File

@ -60,7 +60,7 @@
{<<"rfc3339">>,{pkg,<<"rfc3339">>,<<"0.2.2">>},1},
{<<"scoper">>,
{git,"git@github.com:rbkmoney/scoper.git",
{ref,"810b7287579441c55ca041f884f3fd363666e3cd"}},
{ref,"95643f40dd628c77f33f12be96cf1c39dccc9683"}},
0},
{<<"shamir">>,
{git,"git@github.com:rbkmoney/shamir.git",
@ -78,7 +78,7 @@
{<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.4.1">>},3},
{<<"woody">>,
{git,"git@github.com:rbkmoney/woody_erlang.git",
{ref,"5ee89dd0b2d52ff955a4107a8d9dc0f8fdd365a0"}},
{ref,"358ba355f670ea65fed24568952e6f8919c7293f"}},
0}]}.
[
{pkg_hash,[