-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Make errors more idiomatic, following Roc best-practices #64
Conversation
This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested. If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.
For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
@ageron This is a nice way to show this style of error handling! I think it would be good to avoid asserting that the errors contain specific payloads in the test cases. When the payload is included in the assertion, a user could write a fully functional solution that doesn't pass some of the tests because it returns error tags with different names or payloads. I don't think that a different approach to error handling by the solution should count as the solution being incorrect. To keep the richer error tags in the examples, the assertions could be updated to |
Thanks @isaacvando ! I see your point, but tbh I quite like the fact that the exercises require a specific error: I see it as a learning opportunity for the students. I was personally drawn to Roc specifically for its error management: I've always dreamt of a language that would have safe, granular, and yet convenient error handling. I don't know any other language that handles errors as well as Roc, so I think it's a good idea to demonstrate how it works. As a point of reference, I looked at 10 other tracks:
My takeaway from this little exploration is that we're pretty free to do what we think is best for our language. I'm happy to discuss this further on Roc's Zulip chat, to see what others think. Side note: only about 20% of the exercises have test cases for errors anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ageron Good points, works for me!
The CI error is likely due to using the latest nightly, it requires basic-cli 0.15.0 instead of 14. Merging in main should fix this. |
Extra line at the end
Remove error_map, no longer needed
This conversation started a debate on Roc's Zulip Chat. As a result, here's the latest strategy for handling error test cases:
|
Following a discussion on Roc's Zulip Chat, we decided that the errors should be treated in a more idiomatic way, to teach best practices to the students.
When an error occurs, the recommended return value is:
Err (SomeDescriptiveTag someArgs)
, wheresomeArgs
contains all the information needed for the error handling code, as plain data (not English text, as this is not machine-friendly, and it does not play well with internationalization when displaying a message to the user).If the problem is due to a bad argument, then
SomeDescriptiveTag
should indicate which one(s) and use the past tense, for exampleNumberArgWasNotPositive
.So an idiomatic error would look like
Err (NumberArgWasNotPositive -5)
, NOTErr "The number -5 was not positive"
.