From: Evgeniy Khramtsov Date: Mon, 23 Jan 2017 13:30:16 +0000 (+0300) Subject: Avoid using maps:get/2 to keep compatibility with OTP 17.5 X-Git-Tag: 17.03-beta~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=48d8498dbb7d0313b71a1a79999cfb3024918761;p=ejabberd Avoid using maps:get/2 to keep compatibility with OTP 17.5 --- diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index fd2655632..e6a7f9c39 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -176,10 +176,9 @@ open_session(#{user := U, server := S, resource := R, change_shaper(State), Conn = get_conn_type(State), State1 = State#{conn => Conn, resource => R, jid => JID}, - Prio = try maps:get(pres_last, State) of + Prio = case maps:get(pres_last, State, undefined) of + undefined -> undefined; Pres -> get_priority_from_presence(Pres) - catch _:{badkey, _} -> - undefined end, Info = [{ip, IP}, {conn, Conn}, {auth_module, AuthModule}], ejabberd_sm:open_session(SID, U, S, R, Prio, Info), @@ -211,10 +210,9 @@ process_info(#{lserver := LServer} = State, State1 end; process_info(State, force_update_presence) -> - try maps:get(pres_last, State) of + case maps:get(pres_last, State, error) of + error -> State; Pres -> process_self_presence(State, Pres) - catch _:{badkey, _} -> - State end; process_info(State, Info) -> ?WARNING_MSG("got unexpected info: ~p", [Info]), @@ -498,10 +496,11 @@ init([State, Opts]) -> ejabberd_hooks:run_fold(c2s_init, {ok, State1}, [Opts]). handle_call(get_presence, From, #{jid := JID} = State) -> - Pres = try maps:get(pres_last, State) - catch _:{badkey, _} -> + Pres = case maps:get(pres_last, State, error) of + error -> BareJID = jid:remove_resource(JID), - #presence{from = JID, to = BareJID, type = unavailable} + #presence{from = JID, to = BareJID, type = unavailable}; + P -> P end, reply(From, Pres), State; diff --git a/src/mod_client_state.erl b/src/mod_client_state.erl index 1243e7bf2..f57e3e32d 100644 --- a/src/mod_client_state.erl +++ b/src/mod_client_state.erl @@ -339,7 +339,10 @@ queue_new() -> queue_in(Key, Type, Val, {N, Seq, Q}) -> Seq1 = Seq + 1, Time = {Seq1, p1_time_compat:timestamp()}, - try maps:get(Key, Q) of + case maps:get(Key, Q, error) of + error -> + Q1 = maps:put(Key, [{Type, Time, Val}], Q), + {N + 1, Seq1, Q1}; TypeVals -> case lists:keymember(Type, 1, TypeVals) of true -> @@ -352,9 +355,6 @@ queue_in(Key, Type, Val, {N, Seq, Q}) -> Q1 = maps:put(Key, TypeVals1, Q), {N + 1, Seq1, Q1} end - catch _:{badkey, _} -> - Q1 = maps:put(Key, [{Type, Time, Val}], Q), - {N + 1, Seq1, Q1} end. -spec queue_take(term(), csi_queue()) -> {list(), csi_queue()} | error. diff --git a/src/mod_offline.erl b/src/mod_offline.erl index 43f13a629..61fa65bc5 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -565,10 +565,9 @@ c2s_self_presence({_Pres, #{resend_offline := false}} = Acc) -> Acc; c2s_self_presence({#presence{type = available} = NewPres, State} = Acc) -> NewPrio = get_priority_from_presence(NewPres), - LastPrio = try maps:get(pres_last, State) of + LastPrio = case maps:get(pres_last, State, error) of + error -> -1; LastPres -> get_priority_from_presence(LastPres) - catch _:{badkey, _} -> - -1 end, if LastPrio < 0 andalso NewPrio >= 0 -> route_offline_messages(State); diff --git a/src/xmpp_stream_pkix.erl b/src/xmpp_stream_pkix.erl index 9d3da58be..16b7efa42 100644 --- a/src/xmpp_stream_pkix.erl +++ b/src/xmpp_stream_pkix.erl @@ -40,9 +40,7 @@ authenticate(State) -> -> {ok, binary()} | {error, atom(), binary()}. authenticate(#{xmlns := ?NS_SERVER, sockmod := SockMod, socket := Socket} = State, Authzid) -> - Peer = try maps:get(remote_server, State) - catch _:{badkey, _} -> Authzid - end, + Peer = maps:get(remote_server, State, Authzid), case SockMod:get_peer_certificate(Socket) of {ok, Cert} -> case SockMod:get_verify_result(Socket) of