From ecc0b99d17c67a16cf20344e3f12a9c249a78c3a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 9 Jul 2018 18:37:12 +0300 Subject: Change: when raising NotFound, optionally say which resource --- ick2/persistent.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ick2') diff --git a/ick2/persistent.py b/ick2/persistent.py index 4b216b3..535bdc0 100644 --- a/ick2/persistent.py +++ b/ick2/persistent.py @@ -95,7 +95,7 @@ class FilePersistentState(PersistentStateInterface): def get_resource(self, kind, rid): filename = self._filename(kind, rid) if not os.path.exists(filename): - raise ick2.NotFound() + raise ick2.NotFound(kind=kind, rid=rid) with open(filename, 'r') as f: as_dict = yaml.safe_load(f) return resource_from_dict(as_dict) @@ -116,8 +116,10 @@ class FilePersistentState(PersistentStateInterface): class NotFound(Exception): - def __init__(self): - super().__init__('Resource not found') + def __init__(self, kind=None, rid=None): + super().__init__( + 'Resource {}:{} not found'.format( + kind or "unknown", rid or "unknown")) class Resource: # pragma: no cover -- cgit v1.2.1