diff --git a/PFERD/output_dir.py b/PFERD/output_dir.py index 441717b..c92f4a6 100644 --- a/PFERD/output_dir.py +++ b/PFERD/output_dir.py @@ -503,7 +503,7 @@ class OutputDirectory: try: self._prev_report = Report.load(self._report_path) log.explain("Loaded report successfully") - except (OSError, json.JSONDecodeError, ReportLoadError) as e: + except (OSError, UnicodeDecodeError, json.JSONDecodeError, ReportLoadError) as e: log.explain("Failed to load report") log.explain(str(e)) diff --git a/PFERD/report.py b/PFERD/report.py index 0e0c789..0eaaca9 100644 --- a/PFERD/report.py +++ b/PFERD/report.py @@ -100,10 +100,10 @@ class Report: @classmethod def load(cls, path: Path) -> "Report": """ - May raise OSError, JsonDecodeError, ReportLoadError. + May raise OSError, UnicodeDecodeError, JsonDecodeError, ReportLoadError. """ - with open(path) as f: + with open(path, encoding="utf-8") as f: data = json.load(f) if not isinstance(data, dict): @@ -148,7 +148,7 @@ class Report: "encountered_errors": self.encountered_errors, } - with open(path, "w") as f: + with open(path, "w", encoding="utf-8") as f: json.dump(data, f, indent=2, sort_keys=True) f.write("\n") # json.dump doesn't do this