ID:2529570
 
I don't know why or how this happens, but the following happens:
- A player tries to load their JSON save. It refuses to load, throwing the error runtime error: Unknown value: every time it tries to load another file. It doesn't show on the forums, but there are 31 spaces after it.
- The save files are clean and not corrupted in any way. I know this because it refuses to load "dummy files" that contain a completely static json table that never changes, and loading that file works normally.
The code is this. It crashes on the "json_decode" line.
    var/file_contents = file2text(full_path)
loaded_data = json_decode(file_contents)


Like this isn't consistent. json_decode and file loading works 100% of the time except when this occurs, and when it occurs, the proc just completely stops working and throws that error. I can't even make new files with it when it occurs.

This has never happened before in stable, but I cannot confirm if it's a byond beta bug yet. I need to test my server again tomorrow or something on stable to see if it happens there. Someone has experienced this before, but the solution they used is the solution that I'm actually using now, and it's causing the error. http://www.byond.com/forum/post/2048264

Another thing that just may be coincidence: It is showing 31 spaces after the error. The unicode decimal for a space is 32.


EDIT: Here is also what I am using for file checking. This is called on new when created, so loaded_data on new is always the default data for a player.
    var/full_path = "[get_folder(owner.ckey)][get_file()]"

if(!fexists(full_path))
text2file(json_encode(loaded_data),full_path)

var/file_contents = file2text(full_path)
loaded_data = json_decode(file_contents)
It sounds like the file may have loaded incorrectly, but without a test case to reproduce this I don't know if there's anything I can do.

Outputting the file contents in the event of a failure should be useful, since it may show if the contents as loaded are corrupt.
In response to Lummox JR
Lummox JR wrote:
It sounds like the file may have loaded incorrectly, but without a test case to reproduce this I don't know if there's anything I can do.

Outputting the file contents in the event of a failure should be useful, since it may show if the contents as loaded are corrupt.

The loaded/saved file is not corrupt or anything and works again when the server is restarted. The data that loads when the error occurs is a bunch of spaces (31 of them) in a line. I'm going to code in a thing that does a test that loads and saves a json file in quick succession to see if it can trigger that way.