-
Notifications
You must be signed in to change notification settings - Fork 285
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
[BUG] Unclear message "list index out of range" #3463
Comments
Also a student can get error message list index out of range in level 3. I propose to enhance Hedy to generate error message something like this "List animals contains 3 entries. Index 4 is out of range". What does everyone think? Searching the source code, I think this error message is not generated from within the hedy interpreter! I think its a Python runtime exception error message, hence the lack of localization. Weirdly
|
Ah great catch, thanks!! It is indeed a Python error message leaking out. We aim to not have that happen but it sometimes does. Here also it is quite hard to fix cause this happens at runtime. Best we can do I think is to generate a try-catch and have that output an error (we have done that in other places) @jpelay do you think you can pick this one up? If not I will do it! |
I can try to look into this to see if I can figure it out. Is there a closed issue with similar python runtime message leak I might review? |
Great question! Not one that know of by heart (and I am traveling at the
moment so I can't easily check until Monday) but if you check the generated
Python code for higher levels, you can see that we generate a try catch,
you could take a similar approach here?
|
While I delve into this, I pose another related question if you do not mind. Are lists in hedy supposed to be mutable by index? It does not seem to work (level 16 and above). Was trying to simplify the tic tac toe example into using a single dimension list and could not accomplish it. Current logic has 9 variables (spot_1, spot_2, spot_3 etc.).
|
For @qnojansen 's level 16 bug - unclear message when trying to get a random selection out of an empty list, this kludge in the code would work. It is not very user friendly, but it is better than the default python message. Ideally, the error would include the variable name of the list that is being accessed incorrectly. in hedy.py
Also, in level 16 an error can occur on an out of bounds list access. This is a fix for that:
Finally for my level 3 bug, here is a fix for that. I am sure there are other cases lurking around as well. Probably need to review all unsafe access areas and wrap the code with try/catch more systematically.
|
**Description** Adds an exception to the code generated after transpiling to catch index out of bounds errors. Things to do: - [x] Figure out a way to make the message translatable (`gettext` works inside hedy.py!) - [x] Try to show which line and variable caused the error. (Can show the variable, not the line!) **Fixes #3463** **How to test** Since this is added **after** transpiling, should I add an e2e test? **Checklist** Done? Check if you have it all in place using this list:* - [ ] Contains one of the PR categories in the name - [ ] Describes changes in the format above - [ ] Links to an existing issue or discussion - [ ] Has a "How to test" section If you're unsure about any of these, don't hesitate to ask. We're here to help!
Describe the bug
When choosing an item from an empty list, you get the error message "list index out of range".
Paste the Hedy code & level
Level 16
fruit = []
f = fruit at random
print f
Add a screenshot (optional)
See attached file
Expected behavior
The message should be more descriptive (and in Dutch) so students will understand it.
The text was updated successfully, but these errors were encountered: