Weird corruption issues caused good files to appear un-openable

I had a really odd situation today where I believe one of my scripts got corrupted, and trying to learn what may have done it to avoid it in the future.

I had been editing several of my scripts over the past few days, and yesterday when running one of them I was getting crashes from the apps that did not make sense. I closed all of my open windows, and restarted. Once I restarted, I could no longer open most of my scripts, either in Script Debugger, or in some cases Script Editor.

If I try to open Script A (my main script), I got the following message:

Cannot Open Script
The script “Cover Workflow source.app” failed to open because Mac OS error -1702.
Because this script was saved with Script Debugger, it may be possible to recover its source code.
The recovered source information may be out of date or damaged.  Would you like to proceed with the recovery?

If I took the recovered script, and tried to resave as an application with a new name, I got:

Cannot Save Document
invalid component instance (badComponentInstance:-32767)

I could save it as a .applescript file, but not as an app

What was really weird is that many of the scripts WOULD open fine, until I tried to open Script A. If I opened Script A, got the error above, and even if I choose cancel, then after that other scripts (Script B or Script C for example) would get the same error message. However, if I quit script debugger, and then relaunched it, I could open Script B or C just fine, and even save them. But if I ever opened Script A, it all got wonky again.

Thinking this was somehow related to Script A’s bundle (which has a ton in it), I was able to take the .applescript file and save as a new application in Script Editor (Script Debugger wouldn’t even let me do that from the .applescript file, which really didn’t make sense). It did not have all the bundle contents now, but it does now open and save as an app, and no longer triggers the error message for this or other scripts.

I will manually build back the resources in the bundle that I had before, and hopefully it was just a fluke or something got corrupted, but does anyone know what could have caused this odd behavior of opening a bad file causing both editors to treat ALL other scripts as bad afterward, when they really weren’t?

Until I figured out the pattern was based on me opening the one bad script, I was really starting to panic…

How long is Script A?

3600 lines, which I know is beyond pushing the limits.

I have had issues in the past where it gets too big and just won’t save until I cut some code, but that is not the case here. And odd since when I finally got it to work, it has the same number of lines as the one that is bad.

It sounds like the script is too long/complicated, and AppleScript is getting corrupted trying to open it.

As in the AppleScript Process itself? That would explain why both apps were affected.

OK…I guess I HAVE to rework the script now…