diff --git a/restic_exporter/restic_exporter.py b/restic_exporter/restic_exporter.py index ef551f2..aa09ec4 100644 --- a/restic_exporter/restic_exporter.py +++ b/restic_exporter/restic_exporter.py @@ -60,12 +60,18 @@ class restic_exporter: print(f"{self.metric_name}_{counter}{labels} {float(self.summary[counter])} {self.summary['timestamp']}") def _read_summary_from_json(self, json_file): - with open(json_file, 'r') as file_pointer: - content = file_pointer.readlines() + try: + with open(json_file, 'r') as file_pointer: + content = file_pointer.readlines() + except Exception as error: + self._log.error(f"Error reading file '{json_file}'. Check permissions. {error}") self.summary = {} for line in content: - line_data = json.loads(line) + try: + line_data = json.loads(line) + except json.decoder.JSONDecodeError as error: + self._log.error(f"Error decoding line '{line}'. {error}") if 'message_type' in line_data and line_data['message_type'] == 'summary': self.summary = line_data if 'snapshot_id' in line_data: