Skip to content

Commit

Permalink
add some logging, not enough to release
Browse files Browse the repository at this point in the history
  • Loading branch information
mangiucugna committed Jun 18, 2024
1 parent 485d9c2 commit d1c55cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/json_repair/json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ def parse_string(self) -> Union[str, JSONReturnType]:
if self.get_context() == "object_key" and (
char == ":" or char.isspace()
):
self.log(
"While parsing a string missing the left delimiter in object key context, we found a :, stopping here",
"info",
)
break
elif self.get_context() == "object_value" and char in [",", "}"]:
rstring_delimiter_missing = True
Expand All @@ -389,6 +393,10 @@ def parse_string(self) -> Union[str, JSONReturnType]:
if next_c and next_c in [",", "}"]:
rstring_delimiter_missing = False
if rstring_delimiter_missing:
self.log(
"While parsing a string missing the left delimiter in object value context, we found a , or } and we couldn't determine that a right delimiter was present. Stopping here",
"info",
)
break
string_acc += char
self.index += 1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_repair_json_from_file():
# Write content to the temporary file
with os.fdopen(temp_fd, 'w') as tmp:
tmp.write("{key:value}")
assert(from_file(temp_path, logging=True)) == ({'key': 'value'}, [{'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}, {'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}])
assert(from_file(temp_path, logging=True)) == ({'key': 'value'}, [{'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'context': '{key:value}', 'text': 'While parsing a string missing the left delimiter in object key context, we found a :, stopping here',}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}, {'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'context': '{key:value}', 'text': 'While parsing a string missing the left delimiter in object value context, we found a , or } and we couldn\'t determine that a right delimiter was present. Stopping here'}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}])
finally:
# Clean up - delete the temporary file
os.remove(temp_path)

0 comments on commit d1c55cc

Please sign in to comment.