[PATCH phosphor-objmgr 8/8] Add basic error handling to ObjectMapper
OpenBMC Patches
patches at stwcx.xyz
Thu Nov 5 03:33:34 AEDT 2015
From: Brad Bishop <bradleyb at us.ibm.com>
Raise MapperNotFound for invalid paths supplied to the
DBUS API.
---
phosphor-mapper | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/phosphor-mapper b/phosphor-mapper
index 5bdcd8d..870d9a4 100644
--- a/phosphor-mapper
+++ b/phosphor-mapper
@@ -24,6 +24,10 @@ import gobject
from OpenBMCMapper import Path, IntrospectionParser, PathTree
import OpenBMCMapper
+class MapperNotFoundException(Exception):
+ def __init__(self, msg):
+ super(MapperNotFoundException, self).__init__(msg)
+
class ObjectMapper(dbus.service.Object):
def __init__(self, bus, path,
name_match = OpenBMCMapper.org_dot_openbmc_match,
@@ -133,15 +137,24 @@ class ObjectMapper(dbus.service.Object):
@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):
--
2.6.0
More information about the openbmc
mailing list