microsoft / pxt-arcade

Arcade game editor based on Microsoft MakeCode
https://arcade.makecode.com
MIT License
480 stars 207 forks source link

Unhelpful error when using variable before declaration: "Program Error: sim error: failed cast on null" #2321

Open darzu opened 4 years ago

darzu commented 4 years ago

In this game, it's very hard to find where the issue comes from: https://makecode.com/_J4tTuk0XEDoH

In general, we need a better error message and better indications in the editor of likely causes when this happens.

Screen Shot 2020-08-11 at 9 54 19 AM

This is one of the most common errors in Arcade.

eanders-ms commented 4 years ago

One solution would be to make the message more specific, and clearer: "Variable statusbar used before assignment", and also show an error icon on the block. Do we have enough information to do that? Would it require blocks and JS to share an AST?

darzu commented 4 years ago

We have a way to sourcemap from JS to Blocks. And we get a stack trace. So we should be able to highlight the block. But the blocks error list is maybe the right way to surface this.

But yes, rewording should be the first step.

abchatra commented 4 years ago

This is pending Hristo work of showing error panel which stays and can point to the block right?

abchatra commented 4 years ago

It is pretty clear in typescript that statusbar is null.