Skip to content

Commit

Permalink
fix: Don't redefine builtin exception
Browse files Browse the repository at this point in the history
This is to test my idea from
#176 (comment)
where I've said that I don't think this is necessary since the Elixir
stdlib for Exceptions already has this [1]?

[1] https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/exception.ex#L807
  • Loading branch information
Jesse Claven committed Oct 27, 2022
1 parent 2202dee commit c73b26d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions lib/paginator/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ defmodule Paginator.Config do
:total_count_limit
]

defmodule ArgumentError do
defexception [:message]
end

@default_total_count_primary_key_field :id
@default_limit 50
@minimum_limit 1
Expand Down Expand Up @@ -59,17 +55,17 @@ defmodule Paginator.Config do

def validate!(%__MODULE__{} = config) do
unless config.cursor_fields do
raise(Paginator.Config.ArgumentError, message: "expected `:cursor_fields` to be set")
raise(Paginator.ArgumentError, message: "expected `:cursor_fields` to be set")
end

if !cursor_values_match_cursor_fields?(config.after_values, config.cursor_fields) do
raise(Paginator.Config.ArgumentError,
raise(Paginator.ArgumentError,
message: "expected `:after` cursor to match `:cursor_fields`"
)
end

if !cursor_values_match_cursor_fields?(config.before_values, config.cursor_fields) do
raise(Paginator.Config.ArgumentError,
raise(Paginator.ArgumentError,
message: "expected `:before` cursor to match `:cursor_fields`"
)
end
Expand Down
8 changes: 4 additions & 4 deletions test/paginator/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ defmodule Paginator.ConfigTest do
test "raises ArgumentError when cursor_fields are not set" do
config = Config.new([])

assert_raise Config.ArgumentError, "expected `:cursor_fields` to be set", fn ->
assert_raise ArgumentError, "expected `:cursor_fields` to be set", fn ->
Config.validate!(config)
end
end

test "raises ArgumentError when after cursor does not match the cursor_fields" do
config = Config.new(cursor_fields: [:date], after: complex_after())

assert_raise Config.ArgumentError,
assert_raise ArgumentError,
"expected `:after` cursor to match `:cursor_fields`",
fn ->
Config.validate!(config)
Expand All @@ -146,7 +146,7 @@ defmodule Paginator.ConfigTest do
})
)

assert_raise Config.ArgumentError,
assert_raise ArgumentError,
"expected `:after` cursor to match `:cursor_fields`",
fn ->
Config.validate!(config)
Expand All @@ -170,7 +170,7 @@ defmodule Paginator.ConfigTest do
test "raises ArgumentError when before cursor does not match the cursor_fields" do
config = Config.new(cursor_fields: [:id], before: complex_before())

assert_raise Config.ArgumentError,
assert_raise ArgumentError,
"expected `:before` cursor to match `:cursor_fields`",
fn ->
Config.validate!(config)
Expand Down

0 comments on commit c73b26d

Please sign in to comment.