Sublime Forum

Standard solutions to lost session not working - FIXED - broken JSON

#1

Hi, my linux computer froze and I had to hard-power-off. It had low storage at the time, so this bug may be relevant but now I’ve freed up several gigabytes. Probably worth noting I have my sublime config folder symlinked from my home folder to a folder on an NTFS partition.

In any case, the issue isn’t that the sessions aren’t saving, it’s that they aren’t restoring. I actually have the Auto Save Session.sublime_session file and I checked and it’s got all of the data I’m looking for! (It’s 988K—pretty damn big)

But when I try to replace the session file with it (in ~/.config/sublime-text-3/Local) it doesn’t get loaded when I start ST again.

I’ve tried:

  • hard-quitting ST vs not (before restarting)
  • replacing the Local/Auto Save Session.sublime_session file vs the one that’s just Local/Session.sublime_session, or both

I know this is the right folder because it does get written to when I close ST (I do have some other instances of sublime installed apparently; I have a ~/.config/sublime-text-3x and a ~/.config/sublime-text-3-OLD from awhile ago)

It does successfully restore an arbitrary little session that was generated just created based on the empty state that it’s opening in. Like I installed a new plugin and still had the plugin’s readme open; quit; reopened; readme still there. Just now I noticed one difference between that Session file and the one I was trying to restore being that the one that worked had permissions set to -rwxrwxrwx, whereas the one that wasn’t restoring had -rwxr-xr-x, but I just tried chmod 777 on it and then swapped it in, and again sublime opens empty.

I also just checked and editing the file that does work does open the edited session. I guess maybe I’ll try editing that one and importing most of the Auto Save Session that I want.

This is still a weird bug though. Is there a debug log somewhere of what sublime encounters when I tries & fails to open the session?

To be clear, why I’m prioritizing restoring the session so much is that while I could extract the files I lost, the session also has a bunch of things like autocomplete defaults and so on.

0 Likes

#2

Ahaaaa… I think I’ve found a huge part of the issue. Finally looked in more detail at the file itself and it looks like somehow only half of the file was written. So the JSON ends abruptly without a bunch of closing } and ].

Currently attempting to fix it.

0 Likes

#3

Aha, this worked!

It would have saved me 2 hours (and some stress) if ST had simply complained when opened “Invalid JSON for sublime_session file” and another 10 minutes if ST had given me the option to automatically append appropriate closing tags to the JSON.

I’d also recommend in this situation maybe automatically backing up the corrupted file as a third file in Local/, something like Corrupted Auto Save Session.sublime_session.

For future people encountering this issue, I used this JSON validator to make sure my file was good. It worked even though it was complaining about an invalid character at the end (which I think was just a trailing newline)

FWIW, I believe I turned off my computer using the magic SysReq key & REISUB. But maybe I went a bit fast on the REISUB?

0 Likes

#4

TLDR: If the above didn’t work for you, look into the last file you were editing

I’d just like to add a tip to this discussion.

I’m on Sublime Text 4 (MacOS), and all of sudden today I was working and Sublime froze. I diagnosed the issues, looked online for tips, found the session file and thought it could be the issue. I saw this post but in my case, the JSON file ended properly.

I really didn’t know what to look for in this gigantic file, but after poking for a while I thought I would just try to find the entry corresponding to the last file I was editing and remove it - maybe only that part was corrupted somehow.

Well sure enough, after finding the file (I search for some keywords I knew were in the file I was editing) and removing it from the JSON in the Session.sublime_session, Sublime loaded properly without any issues.

Just thought it might help someone finding this while troubleshooting the same issue.

0 Likes