I have written a python library that has become somewhat complex. Today I noticed
that running my code multiple times in a row without changing a single line of code or anything else, results sometimes in an Exception and sometimes not. The error occurs when parsing a json string using the json.loads
method. (The string in question is valid json format '["1", "6", "12", "14", "36", "44"]'
). Due to the fact that the error appeared after working on the project for a long time and I am not sure what causes it I don't know how to provide a minimum work example. The code is simply of type
result = json.loads(string) # where string is the aforementioned list
When executing the script consecutive times in a row, most of the times the code finished without exception while sometimes it raises
File "myfile.py", line 800, in get
opt = json.loads(opt)
File "/usr/lib64/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python3.10/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
(I have omitted the lines preceding the part which is causing the exception). Unfortunatley I am not sure how to investigate what is going on since the traceback of the error alone gives me no information on what happens differently to when the code runs fine. Are there any ways to compare what the interpreter does between two runs?