C
C#17mo ago
Pork

❔ Error parsing infinity for json, Happens randomly.

Error: I keep getting the error parsing infinity while selecting a random string from my json array, It does this at random and I have no idea why. I have a temporary fix at line 49 but it is making the scene restart multiple times and is just not pleasant one bit Snippet:
void Start()
{
_openAI = new OpenAIApi(openAIKey);

_client.DefaultRequestHeaders.Add("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"{uberDuckKey}:{uberDuckSecret}"))}");

// Pick a random topic
List<string> topics = JsonConvert.DeserializeObject<List<string>>(
File.ReadAllText($"{Application.dataPath}/Scripts/topics.json"));

blacklistPath = $"{Application.dataPath}/Scripts/blacklist.json";
blacklist = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(blacklistPath));
topics.RemoveAll(t => blacklist.Contains(t));

string topic = topics[_random.Next(0, topics.Count)];
void Start()
{
_openAI = new OpenAIApi(openAIKey);

_client.DefaultRequestHeaders.Add("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"{uberDuckKey}:{uberDuckSecret}"))}");

// Pick a random topic
List<string> topics = JsonConvert.DeserializeObject<List<string>>(
File.ReadAllText($"{Application.dataPath}/Scripts/topics.json"));

blacklistPath = $"{Application.dataPath}/Scripts/blacklist.json";
blacklist = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(blacklistPath));
topics.RemoveAll(t => blacklist.Contains(t));

string topic = topics[_random.Next(0, topics.Count)];
Full Code: https://paste.ofcode.org/QYQsqkuvYuU9JgFf8vsGGS
12 Replies
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Pork
PorkOP17mo ago
Error parsing Infinity value. Path '', line 1, position 2 Thats what i get
Tinefol
Tinefol17mo ago
can you provide a sample of json you're parsing Uhm, what bugs me: is there any benefit reading the json dynamically at all?
Pork
PorkOP17mo ago
["cartman dies", "the boys bring communism to Canada", "cartman gets caught eating glass"] not really, I just have a python backend which listens for topics from my streams chats and write it to that json
Tinefol
Tinefol17mo ago
how often does that happen?
Pork
PorkOP17mo ago
usually after 6 parses but it can happen after 2 (its basically random)
Tinefol
Tinefol17mo ago
So, could it be, that the read happens while your python scripts performs a write to a file, and thus json is in a corrupted state and can't be deserialized?
Pork
PorkOP17mo ago
nope happens even when the backend isnt running
Tinefol
Tinefol17mo ago
Okay, I'm not guessing what it is, but I'd probably put a try catch block here, with a logger call on catch, dumping the contents of File.ReadAllText to log I doubt there's a problem with deserializer, more likely there's some problem with file handling
Pork
PorkOP17mo ago
alright i will give it a go, will update you
Tinefol
Tinefol17mo ago
so something like var x = read; try { deserialize } catch { log(exception); log(x); }
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server