From 5300eef27ef637ae34c410f8cc566b5a61e69319 Mon Sep 17 00:00:00 2001
From: Blake Harnden <32446120+bharnden@users.noreply.github.com>
Date: Thu, 27 Aug 2020 10:43:13 -0700
Subject: [PATCH] daemon: added a more specific error to be thrown when a
 service does not exist

---
 daemon/core/errors.py                | 8 ++++++++
 daemon/core/services/coreservices.py | 7 +++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/daemon/core/errors.py b/daemon/core/errors.py
index d299f5ae..4e6ceb92 100644
--- a/daemon/core/errors.py
+++ b/daemon/core/errors.py
@@ -30,3 +30,11 @@ class CoreXmlError(Exception):
     """
 
     pass
+
+
+class CoreServiceError(Exception):
+    """
+    Used when there is an error related to accessing a service.
+    """
+
+    pass
diff --git a/daemon/core/services/coreservices.py b/daemon/core/services/coreservices.py
index 646a433d..590f7950 100644
--- a/daemon/core/services/coreservices.py
+++ b/daemon/core/services/coreservices.py
@@ -25,7 +25,7 @@ from typing import (
 from core import utils
 from core.emulator.data import FileData
 from core.emulator.enumerations import ExceptionLevels, MessageFlags, RegisterTlvs
-from core.errors import CoreCommandError, CoreError
+from core.errors import CoreCommandError, CoreError, CoreServiceError
 from core.nodes.base import CoreNode
 
 if TYPE_CHECKING:
@@ -257,7 +257,10 @@ class ServiceManager:
         :param name: name of the service to retrieve
         :return: service if it exists, None otherwise
         """
-        return cls.services.get(name)
+        service = cls.services.get(name)
+        if service is None:
+            raise CoreServiceError(f"service({name}) does not exist")
+        return service
 
     @classmethod
     def add_services(cls, path: str) -> List[str]: