Skip to content

Resolve CLI elixirc warnings (backport #10459) #10462

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

Closed
wants to merge 2 commits into from
Closed
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
47 changes: 47 additions & 0 deletions deps/rabbitmq_cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
load(":rabbitmqctl.bzl", "rabbitmqctl")
load(":rabbitmqctl_check_formatted.bzl", "rabbitmqctl_check_formatted_test")
load(":rabbitmqctl_compile_warnings_as_errors.bzl", "rabbitmqctl_compile_warnings_as_errors_test")
load(":rabbitmqctl_test.bzl", "rabbitmqctl_test")
load("//:rabbitmq_home.bzl", "rabbitmq_home")
load("//:rabbitmq_run.bzl", "rabbitmq_run")
Expand Down Expand Up @@ -97,6 +98,52 @@ test_suite(
tests = ["check_formatted"],
)

rabbitmqctl_compile_warnings_as_errors_test(
name = "compile_warnings_as_errors",
size = "small",
srcs = [
".formatter.exs",
"config/config.exs",
"mix.exs",
] + glob([
"lib/**/*.ex",
"test/**/*.exs",
]),
data = glob(["test/fixtures/**/*"]),
archives = [
"@hex//:archive",
],
source_deps = {
"@amqp//:sources": "amqp",
"@csv//:sources": "csv",
"@json//:sources": "json",
"@temp//:sources": "temp",
"@x509//:sources": "x509",
},
deps = [
"//deps/amqp_client:erlang_app",
"//deps/rabbit:erlang_app",
"//deps/rabbit_common:erlang_app",
"@observer_cli//:erlang_app",
"@stdout_formatter//:erlang_app",
],
target_compatible_with = select({
"@platforms//os:macos": [
"@platforms//os:macos",
"@elixir_config//:elixir_1_15",
],
"//conditions:default": [
"@platforms//os:linux",
"@elixir_config//:elixir_1_15",
],
}),
)

test_suite(
name = "rabbitmqctl_compile_warnings_as_errors",
tests = ["compile_warnings_as_errors"],
)

plt(
name = "deps_plt",
apps = [
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_cli/lib/rabbitmq/cli/core/command_modules.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule RabbitMQ.CLI.Core.CommandModules do
{:ok, enabled_plugins_file} = PluginsHelpers.enabled_plugins_file(opts)
require Logger

Logger.warn(
Logger.warning(
"Unable to read the enabled plugins file.\n" <>
" Reason: #{inspect(err)}\n" <>
" Commands provided by plugins will not be available.\n" <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.AddUserCommand do

def run(
[username, base64_encoded_password_hash],
%{node: node_name, pre_hashed_password: true} = opts
%{node: node_name, pre_hashed_password: true}
) do
case Base.decode64(base64_encoded_password_hash) do
{:ok, password_hash} ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## This Source Code Form is subject to the terms of the Mozilla Public
## License, v. 2.0. If a copy of the MPL was not distributed with this
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
##
## Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.

defmodule RabbitMQ.CLI.Ctl.Commands.ForceStandaloneKhepriBootCommand do
alias RabbitMQ.CLI.Core.DocGuide

@behaviour RabbitMQ.CLI.CommandBehaviour

use RabbitMQ.CLI.Core.MergesNoDefaults
use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments

def run([], %{node: node_name}) do
ret =
:rabbit_misc.rpc_call(node_name, :rabbit_khepri, :force_shrink_member_to_current_member, [])

case ret do
{:badrpc, {:EXIT, {:undef, _}}} ->
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_usage(),
"This command is not supported by node #{node_name}"}

_ ->
ret
end
end

use RabbitMQ.CLI.DefaultOutput

def usage, do: "force_standalone_khepri_boot"

def usage_doc_guides() do
[
DocGuide.clustering()
]
end

def help_section(), do: :cluster_management

def description(),
do: "Forces node to start as a standalone node"

def banner(_, _), do: nil
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ForgetClusterNodeCommand do
{:error,
"RabbitMQ on node #{node_to_remove} must be stopped with 'rabbitmqctl -n #{node_to_remove} stop_app' before it can be removed"}

<<<<<<< HEAD
=======
{:error, {:failed_to_remove_node, ^atom_name, :unavailable}} ->
{:error, "Node #{node_to_remove} must be running before it can be removed"}

>>>>>>> c285651636 (Resolve elixirc warnings)
{:error, _} = error ->
error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ defmodule RabbitMQ.CLI.Ctl.Commands.JoinClusterCommand do
"Error: cannot cluster node with itself: #{node_name}"}
end

<<<<<<< HEAD
=======
def output({:error, {:node_type_unsupported, db, node_type}}, %{node: _node_name}) do
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_software(),
"Error: `#{node_type}` node type is unsupported by the #{db} by database engine"}
end

def output(
{:error,
{:khepri_mnesia_migration_ex, :all_mnesia_nodes_must_run,
%{all_nodes: nodes, running_nodes: running}}},
_opts
) do
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_software(),
"Error: all mnesia nodes must run to join the cluster, mnesia nodes: #{inspect(nodes)}, running nodes: #{inspect(running)}"}
end

>>>>>>> c285651636 (Resolve elixirc warnings)
use RabbitMQ.CLI.DefaultOutput

def banner([target_node], %{node: node_name}) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

defmodule RabbitMQ.CLI.Ctl.Commands.RenameClusterNodeCommand do
require Integer
alias RabbitMQ.CLI.Core.{DocGuide, Validators}
import RabbitMQ.CLI.Core.DataCoercion
alias RabbitMQ.CLI.Core.DocGuide

@behaviour RabbitMQ.CLI.CommandBehaviour

Expand All @@ -21,6 +20,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.RenameClusterNodeCommand do
:ok
end

<<<<<<< HEAD
def validate_execution_environment(args, opts) do
Validators.chain(
[
Expand All @@ -43,6 +43,10 @@ defmodule RabbitMQ.CLI.Ctl.Commands.RenameClusterNodeCommand do
_, reason ->
{:rename_failed, reason}
end
=======
def run(_nodes, %{node: _node_name}) do
:ok
>>>>>>> c285651636 (Resolve elixirc warnings)
end

use RabbitMQ.CLI.DefaultOutput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Copyright (c) 2016-2023 VMware, Inc. or its affiliates. All rights reserved.

defmodule RabbitMQ.CLI.Ctl.Commands.UpdateClusterNodesCommand do
alias RabbitMQ.CLI.Core.{Config, DocGuide, Helpers}
alias RabbitMQ.CLI.Core.DocGuide

@behaviour RabbitMQ.CLI.CommandBehaviour

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
## This Source Code Form is subject to the terms of the Mozilla Public
## License, v. 2.0. If a copy of the MPL was not distributed with this
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
##
## Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.

defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckIfAnyDeprecatedFeaturesAreUsedCommand do
@behaviour RabbitMQ.CLI.CommandBehaviour

def scopes(), do: [:ctl, :diagnostics]

use RabbitMQ.CLI.Core.AcceptsDefaultSwitchesAndTimeout
use RabbitMQ.CLI.Core.MergesNoDefaults
use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning

def run([], opts) do
are_deprecated_features_used = %{
:classic_queue_mirroring => is_used_classic_queue_mirroring(opts)
}

deprecated_features_list =
Enum.reduce(
are_deprecated_features_used,
[],
fn
{_feat, _result}, {:badrpc, _} = acc ->
acc

{feat, result}, acc ->
case result do
{:badrpc, _} = err -> err
{:error, _} = err -> err
true -> [feat | acc]
false -> acc
end
end
)

# health checks return true if they pass
case deprecated_features_list do
{:badrpc, _} = err -> err
{:error, _} = err -> err
[] -> true
xs when is_list(xs) -> {false, deprecated_features_list}
end
end

def is_used_classic_queue_mirroring(%{node: node_name, timeout: timeout}) do
:rabbit_misc.rpc_call(
node_name,
:rabbit_mirror_queue_misc,
:are_cmqs_used,
[:none],
timeout
)
end

def output(true, %{formatter: "json"}) do
{:ok, %{"result" => "ok"}}
end

def output(true, %{silent: true}) do
{:ok, :check_passed}
end

def output(true, %{}) do
{:ok, "Cluster reported no deprecated features in use"}
end

def output({false, deprecated_features_list}, %{formatter: "json"}) do
{:error, :check_failed,
%{
"result" => "error",
"deprecated_features" => deprecated_features_list,
"message" => "Cluster reported deprecated features in use"
}}
end

def output({false, _deprecated_features_list}, %{silent: true}) do
{:error, :check_failed}
end

def output({false, deprecated_features_list}, _) do
{:error, :check_failed, deprecated_features_list}
end

use RabbitMQ.CLI.DefaultOutput

def usage, do: "check_if_any_deprecated_features_are_used"

def help_section(), do: :observability_and_health_checks

def description(),
do: "Generate a report listing all deprecated features in use"

def banner(_, %{node: _node_name}), do: "Checking if any deprecated features are used ..."
end
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.ListPoliciesThatMatchCommand do
end
end

def output([], %{node: node_name, formatter: "json"}) do
def output([], %{node: _node_name, formatter: "json"}) do
{:ok, %{"result" => "ok", "policies" => []}}
end

def output({:error, :not_found}, %{node: node_name, formatter: "json"}) do
def output({:error, :not_found}, %{node: _node_name, formatter: "json"}) do
{:ok,
%{"result" => "error", "message" => "object (queue, exchange) not found", "policies" => []}}
end

def output(value, %{node: node_name, formatter: "json"}) when is_list(value) do
def output(value, %{node: _node_name, formatter: "json"}) when is_list(value) do
{:ok, %{"result" => "ok", "policies" => value}}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## This Source Code Form is subject to the terms of the Mozilla Public
## License, v. 2.0. If a copy of the MPL was not distributed with this
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
##
## Copyright (c) 2022 VMware, Inc. or its affiliates. All rights reserved.

defmodule RabbitMQ.CLI.Diagnostics.Commands.MetadataStoreStatusCommand do
@behaviour RabbitMQ.CLI.CommandBehaviour
def scopes(), do: [:diagnostics]

def merge_defaults(args, opts), do: {args, Map.merge(%{vhost: "/"}, opts)}

use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning

def run([] = _args, %{node: node_name}) do
:rabbit_misc.rpc_call(node_name, :rabbit_khepri, :status, [])
end

use RabbitMQ.CLI.DefaultOutput

def formatter(), do: RabbitMQ.CLI.Formatters.PrettyTable

def usage() do
"metadata_store_status"
end

def help_section(), do: :observability_and_health_checks

def description(), do: "Displays quorum status of Khepri metadata store"

def banner([], %{node: node_name}),
do: "Status of metadata store on node #{node_name} ..."
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.RemoteShellCommand do
case :shell.start_interactive({node_name, {:shell, :start, []}}) do
:ok -> :ok
{:error, :already_started} -> :ok
{error, _} -> {:error, {:badrpc, :nodedown}}
{:error, _} -> {:error, {:badrpc, :nodedown}}
end

:timer.sleep(:infinity)
Expand Down
Loading