aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_format.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2018-11-27 08:15:22 -0800
committerOle Trøan <otroan@employees.org>2018-11-29 19:18:07 +0000
commit6ccc6e91648312cc210e9b6a18e469e64f4a523f (patch)
treec80d92e7d8c1c28f90cb92d4455c39c52f3b2617 /src/vpp-api/python/vpp_papi/vpp_format.py
parent039a1c2f1401ebf3b38fa9bd55dffff0713b8b98 (diff)
vpp_papi: Add custom exceptions.
This patchset adds and raises the following custom exception classes: * class VPPApiError(Exception): * class VPPNotImplementedError(NotImplementedError): * class VPPIOError(IOError): * class VPPRuntimeError(RuntimeError): * class VPPValueError(ValueError): * class VPPSerializerValueError(ValueError): * class VPPStatsIOError(IOError): * class VPPStatsClientLoadError(RuntimeError): * class VppTransportShmemIOError(IOError): * class VppTransportSocketIOError(IOError) Change-Id: Ia40900fd2dcef148d01125d6c691329fc666901e Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_format.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_format.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_format.py b/src/vpp-api/python/vpp_papi/vpp_format.py
index d020df96188..c6f9477e03f 100644
--- a/src/vpp-api/python/vpp_papi/vpp_format.py
+++ b/src/vpp-api/python/vpp_papi/vpp_format.py
@@ -14,9 +14,16 @@
#
from socket import inet_pton, inet_ntop, AF_INET6, AF_INET
+import socket
+
+
+class VPPFormatError(Exception):
+ pass
class VPPFormat(object):
+ VPPFormatError = VPPFormatError
+
@staticmethod
def format_vl_api_ip6_prefix_t(args):
prefix, len = args.split('/')
@@ -52,7 +59,7 @@ class VPPFormat(object):
try:
return {'un': {'ip6': {'address': inet_pton(AF_INET6, args)}},
'af': int(1)}
- except Exception as e:
+ except socket.error as e:
return {'un': {'ip4': {'address': inet_pton(AF_INET, args)}},
'af': int(0)}
@@ -62,7 +69,7 @@ class VPPFormat(object):
return inet_ntop(AF_INET6, arg.un.ip6.address)
if arg.af == 0:
return inet_ntop(AF_INET, arg.un.ip4.address)
- raise
+ raise VPPFormatError
@staticmethod
def format_vl_api_prefix_t(args):
@@ -80,7 +87,7 @@ class VPPFormat(object):
return "{}/{}".format(inet_ntop(AF_INET,
arg.address.un.ip4.address),
arg.address_length)
- raise
+ raise VPPFormatError
@staticmethod
def format_u8(args):
@@ -101,7 +108,7 @@ class VPPFormat(object):
def unformat_bytes(args):
try:
return args.decode('utf-8')
- except Exception as e:
+ except ValueError as e:
return args
@staticmethod