浏览代码

More user friendly error message when repository key file is not found

Closes #236
Jonas Borgström 10 年之前
父节点
当前提交
b61ba51c0d
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 1 0
      CHANGES
  2. 6 1
      attic/key.py

+ 1 - 0
CHANGES

@@ -7,6 +7,7 @@ Version 0.16
 ------------
 ------------
 
 
 (bugfix release, released on X)
 (bugfix release, released on X)
+- More user friendly error message when repository key file is not found (#236)
 - Fix parsing of iso 8601 timestamps with zero microseconds (#282)
 - Fix parsing of iso 8601 timestamps with zero microseconds (#282)
 
 
 Version 0.15
 Version 0.15

+ 6 - 1
attic/key.py

@@ -17,6 +17,11 @@ class UnsupportedPayloadError(Error):
     """Unsupported payload type {}. A newer version is required to access this repository.
     """Unsupported payload type {}. A newer version is required to access this repository.
     """
     """
 
 
+class KeyfileNotFoundError(Error):
+    """No key file for repository {} found in {}.
+    """
+
+
 class HMAC(hmac.HMAC):
 class HMAC(hmac.HMAC):
     """Workaround a bug in Python < 3.4 Where HMAC does not accept memoryviews
     """Workaround a bug in Python < 3.4 Where HMAC does not accept memoryviews
     """
     """
@@ -221,7 +226,7 @@ class KeyfileKey(AESKeyBase):
                 line = fd.readline().strip()
                 line = fd.readline().strip()
                 if line and line.startswith(cls.FILE_ID) and line[10:] == id:
                 if line and line.startswith(cls.FILE_ID) and line[10:] == id:
                     return filename
                     return filename
-        raise Exception('Key file for repository with ID %s not found' % id)
+        raise KeyfileNotFoundError(repository._location.canonical_path(), get_keys_dir())
 
 
     def load(self, filename, passphrase):
     def load(self, filename, passphrase):
         with open(filename, 'r') as fd:
         with open(filename, 'r') as fd: