@@ -306,6 +306,9 @@ wait_for_leader(Timeout, Retries) ->
306306 throw (Reason )
307307 end .
308308
309+ -spec wait_for_register_projections () -> Ret when
310+ Ret :: ok | no_return ().
311+
309312wait_for_register_projections () ->
310313 wait_for_register_projections (retry_timeout (), retry_limit ()).
311314
@@ -314,10 +317,10 @@ wait_for_register_projections(_Timeout, 0) ->
314317wait_for_register_projections (Timeout , Retries ) ->
315318 rabbit_log :info (" Waiting for Khepri projections for ~tp ms, ~tp retries left" ,
316319 [Timeout , Retries - 1 ]),
317- try
318- register_projections ()
319- catch
320- throw : timeout ->
320+ case register_projections () of
321+ ok ->
322+ ok ;
323+ { error , timeout } ->
321324 wait_for_register_projections (Timeout , Retries - 1 )
322325 end .
323326
@@ -1091,6 +1094,9 @@ if_has_data_wildcard() ->
10911094if_has_data (Conditions ) ->
10921095 # if_all {conditions = Conditions ++ [# if_has_data {has_data = true }]}.
10931096
1097+ -spec register_projections () -> Ret when
1098+ Ret :: ok | timeout_error ().
1099+
10941100register_projections () ->
10951101 RegisterFuns = [fun register_rabbit_exchange_projection /0 ,
10961102 fun register_rabbit_queue_projection /0 ,
@@ -1101,20 +1107,23 @@ register_projections() ->
11011107 fun register_rabbit_bindings_projection /0 ,
11021108 fun register_rabbit_index_route_projection /0 ,
11031109 fun register_rabbit_topic_graph_projection /0 ],
1104- [case RegisterFun () of
1105- ok ->
1106- ok ;
1107- % % Before Khepri v0.13.0, `khepri:register_projection/1,2,3` would
1108- % % return `{error, exists}` for projections which already exist.
1109- {error , exists } ->
1110- ok ;
1111- % % In v0.13.0+, Khepri returns a `?khepri_error(..)` instead.
1112- {error , {khepri , projection_already_exists , _Info }} ->
1113- ok ;
1114- {error , Error } ->
1115- throw (Error )
1116- end || RegisterFun <- RegisterFuns ],
1117- ok .
1110+ rabbit_misc :for_each_while_ok (
1111+ fun (RegisterFun ) ->
1112+ case RegisterFun () of
1113+ ok ->
1114+ ok ;
1115+ % % Before Khepri v0.13.0, `khepri:register_projection/1,2,3`
1116+ % % would return `{error, exists}` for projections which
1117+ % % already exist.
1118+ {error , exists } ->
1119+ ok ;
1120+ % % In v0.13.0+, Khepri returns a `?khepri_error(..)` instead.
1121+ {error , {khepri , projection_already_exists , _Info }} ->
1122+ ok ;
1123+ {error , _ } = Err ->
1124+ Err
1125+ end
1126+ end , RegisterFuns ).
11181127
11191128register_rabbit_exchange_projection () ->
11201129 Name = rabbit_khepri_exchange ,
0 commit comments