pybricks / support

Pybricks support and general discussion
MIT License
109 stars 7 forks source link

[Feature] Visually show runtime errors in block programs #1513

Open laurensvalk opened 8 months ago

laurensvalk commented 8 months ago

Is your feature request related to a problem? Please describe. When an error occurs at runtime, the error gets displayed in the output terminal.

While this does give some information about the problem, you'd have to know Python and figure out the error via the line number.

image

Describe the desired solution It would be nice to parse the error, highlight the block that caused it, along with an explanation.

laurensvalk commented 8 months ago

This is an interesting design problem and technical challenge... It could also be relevant for upstream Blockly.

laurensvalk commented 8 months ago

Blockly has a way to display all block identifier strings as comments in a generated copy of the program. If we parse the line number(s) in the traceback, we could figure out the affected blocks, and highlight the blocks with errors.

I'm not entirely sure how this should work for value blocks, as in the example above. How do we know from the error that the problem is 1/0 rather than the print on the same line?

This also assumes the user hasn't modified the code after running it.

laurensvalk commented 8 months ago

Another approach would be to include the labels as actual parts of the program, but this would drastically increase size and reduce performance as all ids would be printed over the air.

Although a benefit would be that it could include live execution highlighting.