Skip to content

Commit feb4ee6

Browse files
committed
Add missing exceptions documentation
The missing exceptions documentation that was added is related to the code for the "storage_backend" and its API calls. Signed-off-by: Martin Vrachev <[email protected]>
1 parent 43c75d6 commit feb4ee6

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

securesystemslib/hash.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ def digest_filename(filename, algorithm=DEFAULT_HASH_ALGORITHM,
343343
securesystemslib.exceptions.UnsupportedLibraryError, if the given
344344
'hash_library' is unsupported.
345345
346+
securesystemslib.exceptions.StorageError, if the file cannot be opened.
347+
346348
<Side Effects>
347349
None.
348350

securesystemslib/util.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def get_file_details(
5959
securesystemslib.exceptions.FormatError: If hash of the file does not match
6060
HASHDICT_SCHEMA.
6161
62-
securesystemslib.exceptions.Error: If 'filepath' does not exist.
62+
securesystemslib.exceptions.StorageError: The file at "filepath" cannot be
63+
opened or found.
6364
6465
<Returns>
6566
A tuple (length, hashes) describing 'filepath'.
@@ -107,7 +108,8 @@ def get_file_hashes(
107108
securesystemslib.exceptions.FormatError: If hash of the file does not match
108109
HASHDICT_SCHEMA.
109110
110-
securesystemslib.exceptions.Error: If 'filepath' does not exist.
111+
securesystemslib.exceptions.StorageError: The file at "filepath" cannot be
112+
opened or found.
111113
112114
<Returns>
113115
A dictionary conforming to securesystemslib.formats.HASHDICT_SCHEMA
@@ -156,7 +158,8 @@ def get_file_length(
156158
passed a FilesystemBackend will be instantiated and used.
157159
158160
<Exceptions>
159-
securesystemslib.exceptions.Error: If 'filepath' does not exist.
161+
securesystemslib.exceptions.StorageError: The file at "filepath" cannot be
162+
opened or found.
160163
161164
<Returns>
162165
The length, in bytes, of the file at 'filepath'.
@@ -240,6 +243,7 @@ def ensure_parent_dir(
240243
<Exceptions>
241244
securesystemslib.exceptions.FormatError: If 'filename' is improperly
242245
formatted.
246+
securesystemslib.exceptions.StorageError: When folder cannot be created.
243247
244248
<Side Effects>
245249
A directory is created whenever the parent directory of 'filename' does not
@@ -378,6 +382,8 @@ def load_json_file(
378382
securesystemslib.exceptions.Error: If 'filepath' cannot be deserialized to
379383
a Python object.
380384
385+
securesystemslib.exceptions.StorageError: If file cannot be loaded.
386+
381387
IOError in case of runtime IO exceptions.
382388
383389
<Side Effects>

tests/test_util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_B1_get_file_details(self):
6868

6969
for bogus_input in bogus_inputs:
7070
if isinstance(bogus_input, str):
71-
self.assertRaises(securesystemslib.exceptions.Error,
71+
self.assertRaises(securesystemslib.exceptions.StorageError,
7272
securesystemslib.util.get_file_details, bogus_input)
7373
else:
7474
self.assertRaises(securesystemslib.exceptions.FormatError,
@@ -96,7 +96,7 @@ def test_B2_get_file_hashes(self):
9696

9797
for bogus_input in bogus_inputs:
9898
if isinstance(bogus_input, str):
99-
self.assertRaises(securesystemslib.exceptions.Error,
99+
self.assertRaises(securesystemslib.exceptions.StorageError,
100100
securesystemslib.util.get_file_hashes, bogus_input)
101101
else:
102102
self.assertRaises(securesystemslib.exceptions.FormatError,
@@ -123,7 +123,7 @@ def test_B3_get_file_length(self):
123123

124124
for bogus_input in bogus_inputs:
125125
if isinstance(bogus_input, str):
126-
self.assertRaises(securesystemslib.exceptions.Error,
126+
self.assertRaises(securesystemslib.exceptions.StorageError,
127127
securesystemslib.util.get_file_length, bogus_input)
128128
else:
129129
self.assertRaises(securesystemslib.exceptions.FormatError,
@@ -144,6 +144,10 @@ def test_B4_ensure_parent_dir(self):
144144
self.assertRaises(securesystemslib.exceptions.FormatError,
145145
securesystemslib.util.ensure_parent_dir, parent_dir)
146146

147+
# Check that when a folder cannot be created a StorageError is thrown
148+
with self.assertRaises(securesystemslib.exceptions.StorageError):
149+
securesystemslib.util.ensure_parent_dir("/a/file.txt")
150+
147151
# When we call ensure_parent_dir with filepath arg like "a.txt",
148152
# then the directory of that filepath will be an empty string.
149153
# We want to make sure that securesyslib.storage.create_folder()

0 commit comments

Comments
 (0)