Repository: canonical/operator

Issue:
Failing to fetch a resource does not raise the expected exception 
According to the doc string and, as a consequence, the rtfm docs, `charm.model.resources.fetch` is expected to throw a `ModelError`. In reality, it's a `RuntimeError`. We should probably change either the docs or the exception raised.

https://github.com/canonical/operator/blob/9baf2ab3deafcaff5d9c6679cdf1d11fc88e3fa3/ops/model.py#L950-L960

Discussion:

Patch:
diff --git a/ops/model.py b/ops/model.py
index ec99173..c20d883 100644
--- a/ops/model.py
+++ b/ops/model.py
@@ -951,10 +951,10 @@ class Resources:
         """Fetch the resource from the controller or store.
 
         If successfully fetched, this returns a Path object to where the resource is stored
-        on disk, otherwise it raises a ModelError.
+        on disk, otherwise it raises a NameError.
         """
         if name not in self._paths:
-            raise RuntimeError('invalid resource name: {}'.format(name))
+            raise NameError('invalid resource name: {}'.format(name))
         if self._paths[name] is None:
             self._paths[name] = Path(self._backend.resource_get(name))
         return self._paths[name]


Test patch:
diff --git a/test/test_model.py b/test/test_model.py
index d243df3..01325d6 100755
--- a/test/test_model.py
+++ b/test/test_model.py
@@ -490,7 +490,7 @@ class TestModel(unittest.TestCase):
         self.harness.add_resource('foo', 'foo contents\n')
         self.harness.add_resource('bar', '')
 
-        with self.assertRaises(RuntimeError):
+        with self.assertRaises(NameError):
             self.harness.model.resources.fetch('qux')
 
         self.assertEqual(self.harness.model.resources.fetch('foo').name, 'foo.txt')