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

Conversation

rhcarvalho
Copy link
Contributor

@rhcarvalho rhcarvalho commented Sep 2, 2023

Hi there!

@jonatanklosko was faster than I in addressing #325 with #326 -- thanks for the quick fix!

Since I had some changes laying around already, I decided to post them here for feedback/discussion, I wouldn't mind if they are eventually not accepted.

Tests

I noticed Kino.Input.date was lacking tests, and was happy to see @jonatanklosko added one yesterday!

I had a plan to cover more of the possible cases, and so tried some form of table-testing to reduce verbosity. I wonder how others see this type of test code in Elixir, given it also adds some cognitive complexity (unquote, Macro.escape, ...).

The constraints in this case are simple enough that property-based testing would also be a fun exercise :-)

Update: removed tests to keep the PR more focused.

Error messages

Two out of three messages were missing part of what caused the error, making debugging unnecessarily harder.

I tried to make the messages more obvious and easier to interpret by a human when their Livebook cell is spitting out an error on them.

Something like expected :min to be less than :max, got: #{inspect(min)} and #{inspect(max)} is not exactly correct, as :min can also be equal to :max. If I were to continue the existing mathematical pattern, I'd write:

expected :min to be less than or equal :max, got: #{inspect(min)} and #{inspect(max)}

But, then, I thought why not simply state the problem directly: :min is greater than :max. And, when we talk about dates and time, I think the words "before" and "after" might be a better fit (might be a bias from my Go experience, where the time package uses the words "before" and "after").

I would love to hear what are the Elixir-way ideas here, specially if there is a well establish preference.

If my changes are welcome, I could also update the other messages (time, etc) to match.

lib/kino/input.ex Outdated Show resolved Hide resolved
lib/kino/input.ex Outdated Show resolved Hide resolved
lib/kino/input.ex Outdated Show resolved Hide resolved
test/kino/input_test.exs Outdated Show resolved Hide resolved
@rhcarvalho
Copy link
Contributor Author

@jonatanklosko I reviewed the existing error messages and based on your feedback updated the messages for all related functions:

  • Kino.Input.utc_datetime
  • Kino.Input.utc_time
  • Kino.Input.date

Since the "expected ..." format is used in many places, I kept that + your suggestions.

I dropped the tests-related commit so that this PR can be focused on a single thing.

@rhcarvalho rhcarvalho changed the title Kino.Input.date tests and error messages Kino.Input error messages Sep 10, 2023
Copy link
Member

@jonatanklosko jonatanklosko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, please sync with main and it's ready to go :D

For clarity, make the messages more consistent and always include the
argument value that caused the error, making debugging easier.

Replace "less than" and "greater than" language for dates with "before"
and "after". The re-wording also pays closer attention to the three
possible cases: before, equal, or after.
@rhcarvalho
Copy link
Contributor Author

please sync with main and it's ready to go :D

Done!

@jonatanklosko jonatanklosko merged commit fe541ec into livebook-dev:main Sep 11, 2023
1 check passed
@rhcarvalho rhcarvalho deleted the date-range branch September 15, 2023 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants