Skip to content

Use more idiomatic maybe feature #13929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions deps/rabbit/src/rabbit_queue_type_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
check_auto_delete/1,
check_exclusive/1,
check_non_durable/1,
run_checks/2,
erpc_call/5]).

-include_lib("rabbit_common/include/rabbit.hrl").
Expand Down Expand Up @@ -62,16 +61,6 @@ check_non_durable(Q) when not ?amqqueue_is_durable(Q) ->
{protocol_error, precondition_failed, "invalid property 'non-durable' for ~ts",
[rabbit_misc:rs(Name)]}.

run_checks([], _) ->
ok;
run_checks([C | Checks], Q) ->
case C(Q) of
ok ->
run_checks(Checks, Q);
Err ->
Err
end.

-spec erpc_call(node(), module(), atom(), list(), non_neg_integer() | infinity) ->
term() | {error, term()}.
erpc_call(Node, M, F, A, _Timeout)
Expand Down
15 changes: 6 additions & 9 deletions deps/rabbit/src/rabbit_quorum_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
%%

-module(rabbit_quorum_queue).
-feature(maybe_expr, enable).

-behaviour(rabbit_queue_type).
-behaviour(rabbit_policy_validator).
Expand Down Expand Up @@ -248,15 +249,11 @@ handle_event(QName, {From, Evt}, QState) ->
{new | existing, amqqueue:amqqueue()} |
{protocol_error, Type :: atom(), Reason :: string(), Args :: term()}.
declare(Q, _Node) when ?amqqueue_is_quorum(Q) ->
case rabbit_queue_type_util:run_checks(
[fun rabbit_queue_type_util:check_auto_delete/1,
fun rabbit_queue_type_util:check_exclusive/1,
fun rabbit_queue_type_util:check_non_durable/1],
Q) of
ok ->
start_cluster(Q);
Err ->
Err
maybe
ok ?= rabbit_queue_type_util:check_auto_delete(Q),
ok ?= rabbit_queue_type_util:check_exclusive(Q),
ok ?= rabbit_queue_type_util:check_non_durable(Q),
start_cluster(Q)
end.

start_cluster(Q) ->
Expand Down
23 changes: 10 additions & 13 deletions deps/rabbit/src/rabbit_stream_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
%%

-module(rabbit_stream_queue).
-feature(maybe_expr, enable).

-include("mc.hrl").

-behaviour(rabbit_queue_type).
Expand Down Expand Up @@ -137,19 +139,14 @@ is_compatible(_, _, _) ->
-spec declare(amqqueue:amqqueue(), node()) ->
{'new' | 'existing', amqqueue:amqqueue()} |
{protocol_error, Type :: atom(), Reason :: string(), Args :: term()}.
declare(Q0, _Node) when ?amqqueue_is_stream(Q0) ->
case rabbit_queue_type_util:run_checks(
[fun rabbit_queue_type_util:check_auto_delete/1,
fun rabbit_queue_type_util:check_exclusive/1,
fun rabbit_queue_type_util:check_non_durable/1,
fun check_max_segment_size_bytes/1,
fun check_filter_size/1
],
Q0) of
ok ->
create_stream(Q0);
Err ->
Err
declare(Q, _Node) when ?amqqueue_is_stream(Q) ->
maybe
ok ?= rabbit_queue_type_util:check_auto_delete(Q),
ok ?= rabbit_queue_type_util:check_exclusive(Q),
ok ?= rabbit_queue_type_util:check_non_durable(Q),
ok ?= check_max_segment_size_bytes(Q),
ok ?= check_filter_size(Q),
create_stream(Q)
end.

check_max_segment_size_bytes(Q) ->
Expand Down
Loading