diff options
author | Brad Bishop <bradleyb@us.ibm.com> | 2015-11-03 14:46:10 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@us.ibm.com> | 2015-11-04 23:04:49 -0500 |
commit | 3640ecd6d84b6f7245d35e8c930afc5e64910d5c (patch) | |
tree | 695a0005c2951f7d83c1a9fba14d0832bb45726e /phosphor-mapper | |
parent | 77fc9dff1f161d99a33332a0188bb9cd5b7bc352 (diff) | |
download | phosphor-objmgr-3640ecd6d84b6f7245d35e8c930afc5e64910d5c.tar.gz phosphor-objmgr-3640ecd6d84b6f7245d35e8c930afc5e64910d5c.zip |
Add basic error handling to ObjectMapper
Raise MapperNotFound for invalid paths supplied to the
DBUS API.
Diffstat (limited to 'phosphor-mapper')
-rw-r--r-- | phosphor-mapper | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/phosphor-mapper b/phosphor-mapper index 5bdcd8d..e9aa6dc 100644 --- a/phosphor-mapper +++ b/phosphor-mapper @@ -133,15 +133,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): |