[FIXED] Better Error Tracking For Bindings

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?

Hi @leeself, I think we’d consider this type of thing a bug so I’ve moved it to bug reports. (An error message like that shouldn’t happen).

Are you able to post a clone app that demonstrates the issue you faced and we’ll get that fixed.

Hi @stucork! Apologies for the delay in getting back to you on this. I needed to strip the app down before sharing. Here is a stripped down clone app that exhibits the problem: HERE

If you run the app and just hit the “Buy” button on the left, you’ll see the error pop up. It occurs because of a bug in the Customer class in the Customer package. The “new()” method on that class creates a “customer_dict” that is missing the “gender” key, and because the Buy form is attempting to bind a drop down to that key, the error is thrown.

1 Like

Thanks for the clone - it was perfect for helping us track down the bug. Similar future errors should be reported correctly. (This should go live soon)

1 Like