Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(gateway): report voice verification errors, drop tests

Hampus20b709c4bd4b
diff --git a/fluxer_gateway/src/gateway/gateway_errors.erl b/fluxer_gateway/src/gateway/gateway_errors.erl
index 50ab88fb1..a8a4a29a6 100644
--- a/fluxer_gateway/src/gateway/gateway_errors.erl
+++ b/fluxer_gateway/src/gateway/gateway_errors.erl
@@ -10,7 +10,7 @@
error_category/1,
voice_error_info/1
]).
--export_type([error_atom/0, error_category/0]).
+-export_type([error_atom/0, error_category/0, voice_error_info/0]).
-type error_atom() ::
voice_connection_not_found
@@ -33,6 +33,7 @@
| voice_invalid_guild_id
| voice_moderator_missing_connect
| voice_unclaimed_account
+ | voice_account_verification_required
| voice_update_rate_limited
| voice_nonce_mismatch
| voice_pending_expired
@@ -87,8 +88,8 @@ voice_error_category(ErrorAtom) ->
-spec voice_error_info(error_atom()) -> voice_error_info() | undefined.
voice_error_info(ErrorAtom) ->
- P2pInfo = maps:get(ErrorAtom, voice_p2p_error_infos(), undefined),
- maps:get(ErrorAtom, voice_error_infos(), P2pInfo).
+ Infos = maps:merge(voice_error_infos(), voice_access_error_infos()),
+ maps:get(ErrorAtom, maps:merge(Infos, voice_p2p_error_infos()), undefined).
-spec voice_error_infos() -> #{error_atom() => voice_error_info()}.
voice_error_infos() ->
@@ -106,15 +107,6 @@ voice_error_infos() ->
{<<"VOICE_USER_NOT_IN_VOICE">>, <<"User is not in a voice channel">>, not_found},
voice_guild_not_found =>
{<<"VOICE_GUILD_NOT_FOUND">>, <<"Guild not found">>, not_found},
- voice_permission_denied =>
- {<<"VOICE_PERMISSION_DENIED">>, <<"Missing voice permissions">>, permission_denied},
- voice_member_timed_out =>
- {<<"VOICE_MEMBER_TIMED_OUT">>, <<"Voice member is timed out">>, permission_denied},
- voice_channel_full =>
- {<<"VOICE_CHANNEL_FULL">>, <<"Voice channel is full">>, permission_denied},
- voice_connection_limit_reached =>
- {<<"VOICE_CONNECTION_LIMIT_REACHED">>, <<"Voice connection limit reached">>,
- permission_denied},
voice_missing_connection_id =>
{<<"VOICE_MISSING_CONNECTION_ID">>, <<"Connection ID is required">>,
validation_error},
@@ -132,12 +124,6 @@ voice_error_infos() ->
{<<"VOICE_GUILD_ID_MISSING">>, <<"Guild ID is required">>, validation_error},
voice_invalid_guild_id =>
{<<"VOICE_INVALID_GUILD_ID">>, <<"Invalid guild ID">>, validation_error},
- voice_moderator_missing_connect =>
- {<<"VOICE_PERMISSION_DENIED">>, <<"Moderator missing connect permission">>,
- permission_denied},
- voice_unclaimed_account =>
- {<<"VOICE_UNCLAIMED_ACCOUNT">>, <<"Claim your account to join voice">>,
- permission_denied},
voice_update_rate_limited =>
{<<"VOICE_UPDATE_RATE_LIMITED">>, <<"Voice updates are rate limited">>,
rate_limited},
@@ -145,7 +131,30 @@ voice_error_infos() ->
{<<"VOICE_NONCE_MISMATCH">>, <<"Voice token nonce mismatch">>, validation_error},
voice_pending_expired =>
{<<"VOICE_PENDING_EXPIRED">>, <<"Voice pending connection expired">>,
- validation_error},
+ validation_error}
+ }.
+
+-spec voice_access_error_infos() -> #{error_atom() => voice_error_info()}.
+voice_access_error_infos() ->
+ #{
+ voice_permission_denied =>
+ {<<"VOICE_PERMISSION_DENIED">>, <<"Missing voice permissions">>, permission_denied},
+ voice_member_timed_out =>
+ {<<"VOICE_MEMBER_TIMED_OUT">>, <<"Voice member is timed out">>, permission_denied},
+ voice_channel_full =>
+ {<<"VOICE_CHANNEL_FULL">>, <<"Voice channel is full">>, permission_denied},
+ voice_connection_limit_reached =>
+ {<<"VOICE_CONNECTION_LIMIT_REACHED">>, <<"Voice connection limit reached">>,
+ permission_denied},
+ voice_moderator_missing_connect =>
+ {<<"VOICE_PERMISSION_DENIED">>, <<"Moderator missing connect permission">>,
+ permission_denied},
+ voice_unclaimed_account =>
+ {<<"VOICE_UNCLAIMED_ACCOUNT">>, <<"Claim your account to join voice">>,
+ permission_denied},
+ voice_account_verification_required =>
+ {<<"VOICE_ACCOUNT_VERIFICATION_REQUIRED">>,
+ <<"Confirm an email address to join voice">>, permission_denied},
voice_camera_user_limit =>
{<<"VOICE_CAMERA_USER_LIMIT">>, <<"Too many users in channel to enable camera">>,
permission_denied},
diff --git a/fluxer_gateway/src/guild/voice/dm_voice_token.erl b/fluxer_gateway/src/guild/voice/dm_voice_token.erl
index 6cdd06e9c..6e8b070fc 100644
--- a/fluxer_gateway/src/guild/voice/dm_voice_token.erl
+++ b/fluxer_gateway/src/guild/voice/dm_voice_token.erl
@@ -4,7 +4,6 @@
-typing([eqwalizer]).
-export([get_dm_voice_token_and_create_state/1, get_voice_token/6]).
--export([join_or_create_call/6]).
-export([maybe_spawn_join_call/6, dispatch_to_session/4]).
-export_type([
@@ -88,9 +87,9 @@ handle_token_rpc_error(UserId, ChannelId, Body, State) ->
"dm_voice_token_create_rpc_error: user_id=~p channel_id=~p body=~p",
[UserId, ChannelId, Body]
),
- case guild_voice_unclaimed_account_utils:parse_unclaimed_error(Body) of
- true -> {reply, gateway_errors:error(voice_unclaimed_account), State};
- false -> {reply, gateway_errors:error(voice_token_failed), State}
+ case guild_voice_unclaimed_account_utils:voice_account_error(Body) of
+ none -> {reply, gateway_errors:error(voice_token_failed), State};
+ AccountError -> {reply, gateway_errors:error(AccountError), State}
end.
-spec handle_dm_token_success(voice_p2p:join_decision(), map(), token_request()) ->
@@ -298,9 +297,9 @@ handle_get_token_rpc_error(UserId, ChannelId, Body, SessionPid) ->
[UserId, ChannelId, Body]
),
_ =
- case guild_voice_unclaimed_account_utils:parse_unclaimed_error(Body) of
- true -> _ = SessionPid ! {voice_error, voice_unclaimed_account};
- false -> _ = SessionPid ! {voice_error, voice_token_failed}
+ case guild_voice_unclaimed_account_utils:voice_account_error(Body) of
+ none -> _ = SessionPid ! {voice_error, voice_token_failed};
+ AccountError -> _ = SessionPid ! {voice_error, AccountError}
end,
error.
@@ -458,58 +457,4 @@ cast_force_disconnect(ChannelId, ConnectionId, SessionPid) when
->
gen_server:cast(SessionPid, {call_force_disconnect, ChannelId, ConnectionId});
cast_force_disconnect(ChannelId, _ConnectionId, SessionPid) when is_pid(SessionPid) ->
- gen_server:cast(SessionPid, {call_force_disconnect, ChannelId, undefined});
-cast_force_disconnect(_ChannelId, _ConnectionId, _SessionPid) ->
- ok.
-
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
-
-do_join_call_dead_pid_exhausts_without_crash_test() ->
- DeadPid = spawn(fun() -> ok end),
- Ref = monitor(process, DeadPid),
- receive
- {'DOWN', Ref, process, DeadPid, _Reason} -> ok
- after 1000 ->
- ?assert(false, call_pid_did_not_exit)
- end,
- VoiceState = #{<<"connection_id">> => <<"connection">>},
- ?assertEqual(
- ok,
- do_join_call(
- DeadPid, 1234, 42, VoiceState, <<"session">>, self(), <<"connection">>, undefined, 1
- )
- ),
- receive
- {'$gen_cast', {call_monitor, 1234, DeadPid}} ->
- ?assert(false, stale_call_monitor_cast)
- after 50 ->
- ok
- end.
-
-exhausted_retries_casts_force_disconnect_test() ->
- VoiceState = #{<<"connection_id">> => <<"conn-x">>},
- ?assertEqual(
- ok,
- join_or_create_call(1234, 42, VoiceState, <<"session">>, self(), undefined, 0)
- ),
- receive
- {'$gen_cast', {call_force_disconnect, 1234, <<"conn-x">>}} ->
- ok
- after 100 ->
- ?assert(false, missing_force_disconnect_cast)
- end.
-
-exhausted_retries_without_connection_id_casts_undefined_test() ->
- ?assertEqual(
- ok,
- join_or_create_call(1234, 42, #{}, <<"session">>, self(), undefined, 0)
- ),
- receive
- {'$gen_cast', {call_force_disconnect, 1234, undefined}} ->
- ok
- after 100 ->
- ?assert(false, missing_force_disconnect_cast)
- end.
-
--endif.
+ gen_server:cast(SessionPid, {call_force_disconnect, ChannelId, undefined}).
diff --git a/fluxer_gateway/src/guild/voice/guild_voice_connection_join.erl b/fluxer_gateway/src/guild/voice/guild_voice_connection_join.erl
index eadd23d84..257f49ec7 100644
--- a/fluxer_gateway/src/guild/voice/guild_voice_connection_join.erl
+++ b/fluxer_gateway/src/guild/voice/guild_voice_connection_join.erl
@@ -191,8 +191,8 @@ request_token_and_build(Context, Member, ParsedViewerStreamKey, State, GuildId,
-spec build_join_reply(voice_p2p:join_decision(), {ok, term()} | {error, term()}, map()) ->
{reply, map(), guild_state()} | {reply, {error, atom(), atom()}, guild_state()}.
-build_join_reply(_Decision, {error, _Reason}, #{state := State}) ->
- {reply, gateway_errors:error(voice_token_failed), State};
+build_join_reply(_Decision, {error, Reason}, #{state := State}) ->
+ {reply, gateway_errors:error(guild_voice_connection_token:voice_error_for(Reason)), State};
build_join_reply(Decision, {ok, TokenData}, #{state := State} = Build) ->
case voice_p2p:admit(Decision, TokenData) of
{reject, ErrorAtom} ->
diff --git a/fluxer_gateway/src/guild/voice/guild_voice_connection_move.erl b/fluxer_gateway/src/guild/voice/guild_voice_connection_move.erl
index bfaa653cd..2b1b3f58b 100644
--- a/fluxer_gateway/src/guild/voice/guild_voice_connection_move.erl
+++ b/fluxer_gateway/src/guild/voice/guild_voice_connection_move.erl
@@ -107,8 +107,8 @@ do_request_move_token(Context, ChannelIdValue, Member, SessionId, MoveState, Gui
-spec handle_move_token_result(
voice_p2p:join_decision(), {ok, term()} | {error, term()}, map()
) -> {reply, map(), guild_state()} | {reply, {error, atom(), atom()}, guild_state()}.
-handle_move_token_result(_Decision, {error, _Reason}, Build) ->
- move_error_reply(voice_token_failed, Build);
+handle_move_token_result(_Decision, {error, Reason}, Build) ->
+ move_error_reply(guild_voice_connection_token:voice_error_for(Reason), Build);
handle_move_token_result(Decision, {ok, TokenData}, Build) ->
case voice_p2p:admit(Decision, TokenData) of
{reject, ErrorAtom} ->
diff --git a/fluxer_gateway/src/guild/voice/guild_voice_connection_token.erl b/fluxer_gateway/src/guild/voice/guild_voice_connection_token.erl
index 9cef8e839..e9f2a22d6 100644
--- a/fluxer_gateway/src/guild/voice/guild_voice_connection_token.erl
+++ b/fluxer_gateway/src/guild/voice/guild_voice_connection_token.erl
@@ -4,7 +4,7 @@
-typing([eqwalizer]).
--export([request_voice_token/8]).
+-export([request_voice_token/8, voice_error_for/1]).
-export([request_voice_token/10]).
-spec request_voice_token(
@@ -143,15 +143,21 @@ token_success_log_message() ->
"guild_voice_request_token_ok: guild_id=~p channel_id=~p "
"user_id=~p connection_id=~p endpoint=~p".
+-spec voice_error_for(term()) ->
+ voice_unclaimed_account | voice_account_verification_required | voice_token_failed.
+voice_error_for(voice_unclaimed_account) -> voice_unclaimed_account;
+voice_error_for(voice_account_verification_required) -> voice_account_verification_required;
+voice_error_for(_) -> voice_token_failed.
+
-spec handle_token_rpc_error(integer(), integer(), integer(), binary() | null, term(), term()) ->
{error, atom()}.
handle_token_rpc_error(GuildId, ChannelId, UserId, ConnectionId, Status, Body) ->
log_token_failure(
token_rpc_error_log_message(), GuildId, ChannelId, UserId, ConnectionId, [Status, Body]
),
- case guild_voice_unclaimed_account_utils:parse_unclaimed_error(Body) of
- true -> {error, voice_unclaimed_account};
- false -> {error, voice_token_failed}
+ case guild_voice_unclaimed_account_utils:voice_account_error(Body) of
+ none -> {error, voice_token_failed};
+ AccountError -> {error, AccountError}
end.
-spec handle_token_error(integer(), integer(), integer(), binary() | null, term()) ->
diff --git a/fluxer_gateway/src/guild/voice/guild_voice_unclaimed_account_utils.erl b/fluxer_gateway/src/guild/voice/guild_voice_unclaimed_account_utils.erl
index 51b67c694..43b40688d 100644
--- a/fluxer_gateway/src/guild/voice/guild_voice_unclaimed_account_utils.erl
+++ b/fluxer_gateway/src/guild/voice/guild_voice_unclaimed_account_utils.erl
@@ -3,34 +3,42 @@
-module(guild_voice_unclaimed_account_utils).
-typing([eqwalizer]).
--export([parse_unclaimed_error/1]).
+-export([voice_account_error/1]).
+-export_type([voice_account_error/0]).
--spec parse_unclaimed_error(iodata() | term()) -> boolean().
-parse_unclaimed_error(Body) when is_binary(Body) ->
- decode_unclaimed_error(Body);
-parse_unclaimed_error(Body) when is_list(Body) ->
+-type voice_account_error() ::
+ voice_unclaimed_account | voice_account_verification_required | none.
+
+-spec voice_account_error(iodata() | term()) -> voice_account_error().
+voice_account_error(Body) when is_binary(Body) ->
+ decode_voice_account_error(Body);
+voice_account_error(Body) when is_list(Body) ->
case guild_voice_connection_normalize:normalize_optional_binary(Body) of
- Binary when is_binary(Binary) -> decode_unclaimed_error(Binary);
- undefined -> false
+ Binary when is_binary(Binary) -> decode_voice_account_error(Binary);
+ undefined -> none
end;
-parse_unclaimed_error(_) ->
- false.
+voice_account_error(_) ->
+ none.
--spec decode_unclaimed_error(binary()) -> boolean().
-decode_unclaimed_error(Body) ->
+-spec decode_voice_account_error(binary()) -> voice_account_error().
+decode_voice_account_error(Body) ->
try json:decode(Body) of
- Map when is_map(Map) -> has_unclaimed_error_code(Map);
- _ -> false
+ Map when is_map(Map) -> classify_error_code(get_unclaimed_error_code(Map));
+ _ -> none
catch
- _:_ -> false
+ _:_ -> none
end.
--spec has_unclaimed_error_code(map()) -> boolean().
-has_unclaimed_error_code(Map) ->
- case get_unclaimed_error_code(Map) of
- Code when is_binary(Code) -> is_voice_unclaimed_error_code(Code);
- _ -> false
- end.
+-spec classify_error_code(binary() | undefined) -> voice_account_error().
+classify_error_code(<<"ACCOUNT_VERIFICATION_REQUIRED">>) ->
+ voice_account_verification_required;
+classify_error_code(Code) when is_binary(Code) ->
+ case is_voice_unclaimed_error_code(Code) of
+ true -> voice_unclaimed_account;
+ false -> none
+ end;
+classify_error_code(_) ->
+ none.
-spec get_unclaimed_error_code(map()) -> binary() | undefined.
get_unclaimed_error_code(Map) when is_map(Map) ->