[DONE] Ambiguous error message in data binding

I often play games with data bindings to get the result I expect. I ran into a situation today where I got the following error message:

SyntaxError: Syntax error in data binding for never_expires.checked

There was no syntax error in the data binding itself, the syntax error happened internally to Anvil when it tried to build whatever final expression it builds from the data binding.

The root cause was that I had left the default write-back box checked, but was setting the data binding to a constant. Obviously write-back doesn’t work in that situation, but I’d have hoped for an error message that made it more clear what I was doing wrong.

For the interested, I was doing this in the checked data binding for a checkbox:

False if self.item['expires'] else True

It works fine with write-back unchecked, but gives the ambiguous error message when write-back is checked.

This doesn’t seem like a bug. What variable would it write back to?

The bug isn’t the fact that I got an error, the bug is the fact that the error message was ambiguous. It’d have been nice to have gotten a message along the lines of “Write-back unsupported for this data binding” or some such.

1 Like

Yeah. The error is specific to the writeback code it generates (an assignment statement), so it would make sense to highlight that fact.

What a good idea! Done – that’ll go live next week :slight_smile:

2 Likes

I just saw the new error message (because apparently I keep doing the same thing!), and I have to say that’s lovely. I immediately knew what was going on because of the error message, instead of having to puzzle through it again.

Thanks!

2 Likes