summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Greenan <kmg@box.com>2015-07-12 09:32:17 -0700
committerKevin Greenan <kmg@box.com>2015-07-12 09:32:17 -0700
commit0acbcd251339a6dfb1fdfe3a3f2ad1ce1df67406 (patch)
tree40859dc46218ac1b30f3c06ee442d3d7207dbaea
parent2d0ff6ee21fbca9030220874f5902caf7abb2def (diff)
downloadpyeclib-0acbcd251339a6dfb1fdfe3a3f2ad1ce1df67406.tar.gz
Example of passing different exception when decode has insifficient fragments.
-rw-r--r--pyeclib/core.py9
-rw-r--r--pyeclib/ec_iface.py9
2 files changed, 14 insertions, 4 deletions
diff --git a/pyeclib/core.py b/pyeclib/core.py
index 17dfa75..d5acdac 100644
--- a/pyeclib/core.py
+++ b/pyeclib/core.py
@@ -21,7 +21,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from ec_iface import PyECLib_FRAGHDRCHKSUM_Types, ECDriverError
+from ec_iface import PyECLib_FRAGHDRCHKSUM_Types, ECDriverError, ECDriverInsufficientFragmentError
import math
import pyeclib_c
from pyeclib_c import error as PyECLibError
@@ -80,12 +80,15 @@ class ECPyECLibDriver(object):
raise ECDriverError("Invalid fragment payload in ECPyECLibDriver.decode")
if len(fragment_payloads) < self.k:
- raise ECDriverError("Not enough fragments given in ECPyECLibDriver.decode")
+ raise ECDriverInsufficientFragmentError("Not enough fragments given in ECPyECLibDriver.decode")
try:
ret = pyeclib_c.decode(self.handle, fragment_payloads, fragment_len, ranges, force_metadata_checks)
except PyECLibError as e:
- raise ECDriverError(e)
+ if e.message.find("Insufficient number of fragments") < 0:
+ raise ECDriverError(e)
+ else:
+ raise ECDriverInsufficientFragmentError(e)
# Was there an error decoding
if ret is None:
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 70c3386..d802dd7 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -113,7 +113,6 @@ class PyECLib_FRAGHDRCHKSUM_Types(PyECLibEnum):
# Generic ECDriverException
class ECDriverError(Exception):
-
def __init__(self, error):
try:
self.error_str = str(error)
@@ -123,6 +122,14 @@ class ECDriverError(Exception):
def __str__(self):
return self.error_str
+# Exception specifying insufficient fragments specified for
+# decode or reconstruction
+class ECDriverInsufficientFragmentError(Exception):
+ def __init__(self, *args):
+ super(ECDriverInsufficientFragmentError, self).__init__(*args)
+ def __str__(self):
+ return self.error_str
+
# Main ECDriver class
class ECDriver(object):