exercism / python

Exercism exercises in Python.
https://exercism.org/tracks/python
MIT License
1.9k stars 1.27k forks source link

[Practice Exercises] Add Guidance for Exercises that Require Raising Errors or Error handling #2563

Closed BethanyG closed 2 years ago

BethanyG commented 3 years ago

When we transitioned to the current version of exercism, we removed the generic "raising exceptions" notices from all the exercise READMEs. We felt they were adding confusion and leading students to insert error raising and handling in places where they should not have been inserting it.

For the Python track, we were (and are!) planning error handling concept exercises to help students learn how to raise and handle errors properly in their code.

But those exercises are still in process, and we have 42 practice exercises that test for error handling in one way or another.
37 of these include JinJa2 test generation templates.

As a stopgap while we create the error handling concept exercises, we need to create practice exercise .docs/instructions.append.md files for the 42 exercises that add back a blurb about how to raise an exception. The original vs proposed language for the instructions.append.md is at the bottom, but is open to any edits that make sense and help student understanding.

For the 37 JinJa2 exercises, we will need to modify the test generation templates to test for a meaningful exception message, and not just the presence of any exception. We'll then need to regenerate those test files.

For the 5 exercises that remain, we will need to hand-edit the test files as opposed to editing a generation template.

Recommend that a PR for ONE exercise be done as a first pass to make sure the changes do indeed makes sense, then the remainder of them can be done.

These are the 42 practice exercises in question:

PR 2685


PR 2691


PR 2692


PR 2715


PR 2716


PR 2725


PR 2727


PR 2734

[ORIGINAL]

Exception messages

Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include a message.

To raise a message with an exception, just write it as an argument to the exception type. For example, instead of raise Exception, you should write:

raise Exception("Meaningful message indicating the source of the error")


[Suggested Changes]

Exception messages

Sometimes it is necessary to raise an exception. When you do this, you should always include a meaningful error message to indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. For situations where you know that the error source will be a certain type, you can choose to rase one of the built in error types, but should still include a meaningful message.

This particular exercise requires that you use the raise statement to "throw" an exception. The tests will only pass if you both raise the exception and include a message with it.

To raise an exception with a message, write the message as an argument to the exception type:

raise Exception("Meaningful message indicating the source of the error")
github-actions[bot] commented 3 years ago

This issue has been automatically marked as abandoned 🏚 because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

BethanyG commented 3 years ago

I can only hope to abandon this. Nice try, gitbot, but I think this needs to stay open. 😞

BethanyG commented 2 years ago

Related website issue that might prevent these from showing right away: https://github.com/exercism/exercism/issues/6063. Should be fixed soon (probably before these are all done).