Add basic error handling to ObjectMapper
Raise MapperNotFound for invalid paths supplied to the
DBUS API.
diff --git a/OpenBMCMapper.py b/OpenBMCMapper.py
index 3e7a745..ef49637 100644
--- a/OpenBMCMapper.py
+++ b/OpenBMCMapper.py
@@ -24,6 +24,10 @@
MAPPER_PATH = '/org/openbmc/objectmapper/objectmapper'
ENUMERATE_IFACE = 'org.openbmc.Object.Enumerate'
+class MapperNotFoundException(Exception):
+ def __init__(self, msg):
+ super(MapperNotFoundException, self).__init__(msg)
+
class Path:
def __init__(self, path):
self.parts = filter(bool, path.split('/'))
diff --git a/phosphor-mapper b/phosphor-mapper
index 5bdcd8d..e9aa6dc 100644
--- a/phosphor-mapper
+++ b/phosphor-mapper
@@ -133,15 +133,24 @@
@dbus.service.method(OpenBMCMapper.MAPPER_IFACE, 's', 'a{sas}')
def GetObject(self, path):
- return self.cache[path]
+ o = self.cache.get(path)
+ if not o:
+ raise MapperNotFoundException(path)
+ return o
@dbus.service.method(OpenBMCMapper.MAPPER_IFACE, 'si', 'as')
def GetSubTreePaths(self, path, depth):
- return self.cache.iterkeys(path, depth)
+ try:
+ return self.cache.iterkeys(path, depth)
+ except KeyError:
+ raise MapperNotFoundException(path)
@dbus.service.method(OpenBMCMapper.MAPPER_IFACE, 'si', 'a{sa{sas}}')
def GetSubTree(self, path, depth):
- return { x:y for x, y in self.cache.dataitems(path, depth) }
+ try:
+ return { x:y for x, y in self.cache.dataitems(path, depth) }
+ except KeyError:
+ raise MapperNotFoundException(path)
class BusWrapper:
def __init__(self, bus):