Browse Source

Add error handling docstrings.

Dan Helfman 20 hours ago
parent
commit
e02c4be493
1 changed files with 6 additions and 1 deletions
  1. 6 1
      borgmatic/hooks/data_source/dump.py

+ 6 - 1
borgmatic/hooks/data_source/dump.py

@@ -42,11 +42,13 @@ def write_data_source_dumps_metadata(borgmatic_runtime_directory, hook_name, dum
     borgmatic.actions.restore.Dump instances of dump metadata, write a metadata file describing all
     borgmatic.actions.restore.Dump instances of dump metadata, write a metadata file describing all
     of those dumps. This metadata is being dumped so that it's available upon restore, e.g. to
     of those dumps. This metadata is being dumped so that it's available upon restore, e.g. to
     support the user selecting which data source(s) should be restored.
     support the user selecting which data source(s) should be restored.
+
+    Raise ValueError if writing to the file results in an operating system error.
     '''
     '''
     dumps_metadata_path = os.path.join(borgmatic_runtime_directory, hook_name, 'dumps.json')
     dumps_metadata_path = os.path.join(borgmatic_runtime_directory, hook_name, 'dumps.json')
 
 
     try:
     try:
-        with open( dumps_metadata_path, 'w') as metadata_file:
+        with open(dumps_metadata_path, 'w') as metadata_file:
             json.dump([dump._asdict() for dump in dumps_metadata], metadata_file, sort_keys=True)
             json.dump([dump._asdict() for dump in dumps_metadata], metadata_file, sort_keys=True)
     except OSError as error:
     except OSError as error:
         raise ValueError(f'Error writing to dumps metadata at {dumps_metadata_path}: {error}')
         raise ValueError(f'Error writing to dumps metadata at {dumps_metadata_path}: {error}')
@@ -56,6 +58,9 @@ def parse_data_source_dumps_metadata(dumps_json, dumps_metadata_path):
     '''
     '''
     Given a dumps metadata JSON string as extracted from an archive, parse it into a tuple of
     Given a dumps metadata JSON string as extracted from an archive, parse it into a tuple of
     borgmatic.actions.restore.Dump instances and return them.
     borgmatic.actions.restore.Dump instances and return them.
+
+    Raise ValueError if parsing the JSON results in a JSON decode error or the data does not have
+    the expected keys.
     '''
     '''
     try:
     try:
         return tuple(borgmatic.actions.restore.Dump(**dump) for dump in json.loads(dumps_json))
         return tuple(borgmatic.actions.restore.Dump(**dump) for dump in json.loads(dumps_json))