Tips to prevent Anvil IDE getting into bad state (JSON Parse error) in an app

Hi everyone,

I hope you are well and may be able to help. I seem to have a recurring problem with the Anvil Beta IDE when I develop locally using git branches and push code to Anvil. I don’t think it is applicable to the old IDE because that doesn’t support git branches?.

What I’m trying to do:
I tend to develop locally for backend type work and then push to Anvil (acting as origin) when I need to work on UI interfaces. I understand that this isn’t the “conventional” workflow with Anvil and using it this way is likely a common source of breaking the IDE. However, being able to run tests locally and using git branches (git-flow) is valuable as well as some local development niceties (pre-commit hooks).

What I’ve tried and what’s not working:
So at random points (sometimes happens within days of each other, sometimes happily works for a few weeks) it seems that the IDE gets itself in a bad state (only when I am working in the IDE) and comes up with an error: “JSON.parse: unexpected character at line 1 column 1 of the JSON data”. There doesn’t appear to be any one thing I am doing in the IDE to trigger this and it has been hard to replicate or narrow down to a specific cause. I haven’t tried to dig much to see what is happening but it appears to be an Anvil internal state as none of the files available by git have changed. Changing browsers or running in private mode doesn’t seem to change anything.

I can “resolve” it by pulling the code, creating a new app in the IDE and then pushing the code to the new app (it then works as before).

I am unsuspicious of the code itself as I can get it to successfully run in docker locally and in Anvil when pushed to a fresh app.

Has anyone had this happen to them? If so have you manage to nail down a cause or have any tips to prevent this from happening? Am I missing something obvious?

Thank you,

Chris

If the problem is in the IDE, a hard refresh with Ctrl+F5 should fix it. And this could explain why the problem is only on the beta IDE.

If the problem is in the repository, then it should affect both the new and old IDE. The old IDE only sees the master and the published branches, but it does use the same repository.

It has happened to me that some yaml file was corrupted and the app wouldn’t load anymore. I don’t remember what I was doing, but whatever it was, I stopped doing it and I never had similar problems in ages. Some diff tools don’t see those changes if they only affect blanks or indentation. Make sure that you include all in the diff when you compare the revision you just pushed to the last one that was working.

Have you tried to revert to an older version and push it, to see if the IDE works with that?

Hi @burrows.ca,

Given that you’re editing UI YAML files locally, it sounds very much like you’ve run into the problem @stefano.menci describes:

It has happened to me that some yaml file was corrupted and the app wouldn’t load anymore

If you push malformed YAML files to your repository, the IDE will be entirely unable to load them. I suggest reverting to older versions until you find the change which introduced the syntax error, then inspecting the diff for hints!

Hi @stefano.menci & @meredydd,

Thank you very much both for the replies. I have done some digging so I can do a better job of explaining what is going on.

Just to cover your suggestions and guidance:

  • Crtl + F5 unfortunately doesn’t change anything
  • I use the new IDE as it supports git branches but the old IDE fails to open the app as well when it gets into this state: “Could not open app - You may have been logged out - please refresh the page.”
  • Reverting to earlier commits (going a long way back) doesn’t solve the issue
  • I try to only touch the client code in the anvil IDE, looking back - I don’t think I have touched any of the YAMLs in local development in any of my commits
  • Pulling the code from the app, and then pushing it to a new app without modification, works fine - so that leads me to believe my source code & branch are ok.

I should have done this earlier (it probably would have shortcutted things) but looking closer at the browser dev tools for my app that doesn’t work - I can see a request to: https://anvil.works/ide/apps/`APP_ID` produces a 500 Internal Server Error. So something has gone wrong somewhere.

This happens often enough to me that suggests I am doing something wrong or there is something up with my setup that gets an app into this state.

Let me know if I can provide more information that will help with this.

Chris