Skip to content

Commit

Permalink
Tweak error messages introduced in 0910060
Browse files Browse the repository at this point in the history
  • Loading branch information
g-andrade committed Oct 12, 2024
1 parent 0910060 commit c475e75
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions lib/sqids/hacks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,53 @@ defmodule Sqids.Hacks do
@spec raise_exception_if_missed_desired_options(Sqids.opts(), Sqids.opts(), module) :: :ok
def raise_exception_if_missed_desired_options(opts, desired_opts, using_mod) do
missed_opts = Sqids.different_opts(opts, desired_opts)
using_mod_str = inspect(using_mod)

if missed_opts === [] do
Logger.warning("""
Direct call of #{inspect(using_mod)}.child_spec/1 may lead to unintended results in the future.
Direct call of #{using_mod_str}.child_spec/1 may lead to unintended results in the future.
Update #{inspect(using_mod)}'s entry under your supervisor,
Update #{using_mod_str}'s entry under your supervisor,
from:
[
#{inspect(using_mod)}
#{using_mod_str}
]
To:
[
#{inspect(using_mod)}.child_spec()
#{using_mod_str}.child_spec()
]
Apologies for the disruption. Context for the issue:
* https://github.com/sqids/sqids-elixir/issues/32
""")
else
raise """
Inconsistent options for #{using_mod_str}.
The following Sqids options were declared but are not being used:
* #{inspect(missed_opts, pretty: true)}
IF YOU START USING THEM NOW IT WILL BREAK COMPATIBILITY WITH PREVIOUSLY ENCODED IDS.
In #{using_mod_str}.child_spec/0 you declared the following options:
* #{inspect(desired_opts, pretty: true)}
How can I fix this?
However, these are the ones in use:
* #{inspect(opts, pretty: true)}
First step is optional: if you don't want to breaking existing IDs,
update your #{inspect(using_mod)} options to match the ones in use:
```
defmodule #{using_mod} do
def child_spec do
# Was: child_spec(#{inspect(desired_opts)})
Noticeably, the following are missing or different:
* #{inspect(missed_opts, pretty: true)}
child_spec(
#{inspect(opts, pretty: true)}
)
end
end
```
---------
You can solve this by changing #{using_mod_str}.child_spec/0 in either of two ways:
A) SAFEST: declare the options in use: #{inspect(opts)}, or
B) UNSAFE: keep the options you intended, WHICH BREAKS COMPATIBILITY
WITH PREVIOUSLY ENCODED IDs.
Second step: update #{inspect(using_mod)}'s entry under your supervisor, from:
Then, update #{using_mod_str}'s entry under its Supervisor, from:
[
#{inspect(using_mod)}
#{using_mod_str}
]
To:
[
#{inspect(using_mod)}.child_spec()
#{using_mod_str}.child_spec()
]
Apologies for the disruption. Context for the issue:
Expand Down

0 comments on commit c475e75

Please sign in to comment.