Skip to content

Commit 7e8ecc9

Browse files
committed
CLI: Don't use regex as module attributes
When trying to use OTP28.0-rc1, Elixir fails to compile these modules because a module attribute cannot be a regex. It is not yet clear whether it's something to be fixed in Elixir for OTP28 compatibility or something that accidentally worked in the past, but either way, using a string as an attribute is equally good and works all OTP versions, including OTP28.0-rc1. ``` == Compilation error in file lib/rabbitmq/cli/core/command_modules.ex == ** (ArgumentError) cannot inject attribute @commands_ns into function/macro because cannot escape #Reference<0.2201422310.1333657602.13657>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, PIDs and remote functions in the format &Mod.fun/arity (elixir 1.18.2) lib/kernel.ex:3729: Kernel.do_at/5 (elixir 1.18.2) expanding macro: Kernel.@/1 lib/rabbitmq/cli/core/command_modules.ex:133: RabbitMQ.CLI.Core.CommandModules.make_module_map/2 ```
1 parent c470661 commit 7e8ecc9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/core/command_modules.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule RabbitMQ.CLI.Core.CommandModules do
1111

1212
import RabbitMQ.CLI.Core.CodePath
1313

14-
@commands_ns ~r/RabbitMQ.CLI.(.*).Commands/
14+
@commands_ns ~S"RabbitMQ.CLI.(.*).Commands"
1515

1616
def module_map(opts \\ %{}) do
1717
Application.get_env(:rabbitmqctl, :commands) || load(opts)
@@ -130,7 +130,7 @@ defmodule RabbitMQ.CLI.Core.CommandModules do
130130
end
131131

132132
defp make_module_map(modules, scope) when modules != nil do
133-
commands_ns = Regex.recompile!(@commands_ns)
133+
commands_ns = Regex.compile!(@commands_ns)
134134

135135
modules
136136
|> Enum.filter(fn mod ->
@@ -212,7 +212,7 @@ defmodule RabbitMQ.CLI.Core.CommandModules do
212212
defp command_scopes(cmd) do
213213
case CommandBehaviour.scopes(cmd) do
214214
nil ->
215-
Regex.recompile!(@commands_ns)
215+
Regex.compile!(@commands_ns)
216216
|> Regex.run(to_string(cmd), capture: :all_but_first)
217217
|> List.first()
218218
|> to_snake_case

deps/rabbitmq_cli/lib/rabbitmq/cli/core/os_pid.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
defmodule RabbitMQ.CLI.Core.OsPid do
88
@external_process_check_interval 1000
99

10-
@pid_regex ~r/^\s*(?<pid>\d+)/
10+
@pid_regex ~S"^\s*(?<pid>\d+)"
1111

1212
#
1313
# API
@@ -27,7 +27,7 @@ defmodule RabbitMQ.CLI.Core.OsPid do
2727
def read_pid_from_file(pidfile_path, should_wait) do
2828
case {:file.read_file(pidfile_path), should_wait} do
2929
{{:ok, contents}, _} ->
30-
pid_regex = Regex.recompile!(@pid_regex)
30+
pid_regex = Regex.compile!(@pid_regex)
3131

3232
case Regex.named_captures(pid_regex, contents)["pid"] do
3333
# e.g. the file is empty

0 commit comments

Comments
 (0)