Skip to content
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

Kino.Input error messages #327

Merged
merged 1 commit into from
Sep 11, 2023
Merged
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
24 changes: 15 additions & 9 deletions lib/kino/input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ defmodule Kino.Input do

if min && max && NaiveDateTime.compare(min, max) == :gt do
raise ArgumentError,
"expected :min to be less than :max, got: #{inspect(min)} and #{inspect(max)}"
"expected a non-empty range, but :min (#{inspect(min)}) is after :max (#{inspect(max)})"
end

assert_default_value!(
Expand All @@ -287,11 +287,13 @@ defmodule Kino.Input do
)

if min && default && NaiveDateTime.compare(default, min) == :lt do
raise ArgumentError, "expected :default to be bigger than :min, got: #{inspect(default)} "
raise ArgumentError,
"invalid :default, #{inspect(default)} is before :min (#{inspect(min)})"
end

if max && default && NaiveDateTime.compare(default, max) == :gt do
raise ArgumentError, "expected :default to be smaller than :max, got: #{inspect(default)}"
raise ArgumentError,
"invalid :default, #{inspect(default)} is after :max (#{inspect(max)})"
end

new(%{
Expand Down Expand Up @@ -333,17 +335,19 @@ defmodule Kino.Input do

if min && max && Time.compare(min, max) == :gt do
raise ArgumentError,
"expected :min to be less than :max, got: #{inspect(min)} and #{inspect(max)}"
"expected a non-empty range, but :min (#{inspect(min)}) is after :max (#{inspect(max)})"
end

assert_default_value!(default, "be %Time{} or nil", &(is_struct(&1, Time) or &1 == nil))

if min && default && Time.compare(default, min) == :lt do
raise ArgumentError, "expected :default to be bigger than :min, got: #{inspect(default)}"
raise ArgumentError,
"invalid :default, #{inspect(default)} is before :min (#{inspect(min)})"
end

if max && default && Time.compare(default, max) == :gt do
raise ArgumentError, "expected :default to be smaller than :max, got: #{inspect(default)}"
raise ArgumentError,
"invalid :default, #{inspect(default)} is after :max (#{inspect(max)})"
end

new(%{
Expand Down Expand Up @@ -384,17 +388,19 @@ defmodule Kino.Input do

if min && max && Date.compare(min, max) == :gt do
raise ArgumentError,
"expected :min to be less than :max, got: #{inspect(min)} and #{inspect(max)}"
"expected a non-empty range, but :min (#{inspect(min)}) is after :max (#{inspect(max)})"
end

assert_default_value!(default, "be %Date{} or nil", &(is_struct(&1, Date) or &1 == nil))

if min && default && Date.compare(default, min) == :lt do
raise ArgumentError, "expected :default to be bigger than :min, got: #{inspect(default)}"
raise ArgumentError,
"invalid :default, #{inspect(default)} is before :min (#{inspect(min)})"
end

if max && default && Date.compare(default, max) == :gt do
raise ArgumentError, "expected :default to be smaller than :max, got: #{inspect(default)}"
raise ArgumentError,
"invalid :default, #{inspect(default)} is after :max (#{inspect(max)})"
end

new(%{
Expand Down
Loading