Hello! First let me say how much I love Anvil, and how much easier its made my life and work (everything from handling timezones to validating forms).
I recently ran into a bug in my code with a very opaque error message, and couldn’t find anything in the forums to help. I managed to track down the bug, but was surprised that the error message wasn’t clearer. Here was the situation:
I have a form called BuyForm. It includes some input fields and a few reusable components. After making a few small changes (adding some fields and moving a few things around) the form suddenly stopped loading when I would click on its nav link with this warning:
ExternalError: TypeError: Cannot read property ‘_anvil’ of undefined
The trace took me to BuyForm’s init_components line and stopped there. Thus, I knew somewhere on this form, there was something that was undefined that I was calling on. I wasn’t sure what the “_anvil” property was, when it would be read, or what it would be read from, so that was no help in tracking down the bug.
After going through a process of deleting and re-adding pieces of BuyForm to track it down, I pinpointed a reusable component called CustomerForm. Then, once again, by process of deleting and re-adding the 20 or so fields on this form, I got it down to a single drop down input. After a few more minutes of fiddling and pulling my hair out, I realized that I hadn’t initialized that one key in the form’s self.item dict (duh!), and so the form was throwing an error when I tried to bind to it.
I was surprised that the error message didn’t mention the actual form where the error was, or that it was a component attempting to bind to a non-existent key, or which component was trying to do the binding. Is there any way to make the error reporting with reusable components better? Or a better method for hunting bugs like this down?