Skip to content

Commit

Permalink
Merge pull request #22 from doronz88/bugfix/bad-json
Browse files Browse the repository at this point in the history
crash_report: handle badly-formatted json files
  • Loading branch information
doronz88 authored Nov 16, 2023
2 parents af0bb77 + 85770b9 commit e01a15e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pycrashreport/crash_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from enum import Enum
from io import StringIO
from typing import List, Optional, Mapping, IO
from typing import IO, List, Mapping, Optional

import click
from cached_property import cached_property
Expand Down Expand Up @@ -192,7 +192,12 @@ def __init__(self, metadata: Mapping, data: str, filename: str = None):
def _parse(self):
self._is_json = False
try:
self._data = json.loads(self._data)
modified_data = self._data
if '\n \n' in modified_data:
modified_data, rest = modified_data.split('\n \n', 1)
rest = '",' + rest.split('",', 1)[1]
modified_data += rest
self._data = json.loads(modified_data)
self._is_json = True
except json.decoder.JSONDecodeError:
pass
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from pathlib import Path

from pycrashreport.crash_report import Frame, Register, get_crash_report_from_file, BugType
from pycrashreport.crash_report import BugType, Frame, Register, get_crash_report_from_file


def test_non_symbolicated_ios14():
Expand Down

0 comments on commit e01a15e

Please sign in to comment.