bt2: change some bt2.CreationError usages to ValueError
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 5 Jun 2019 18:11:37 +0000 (14:11 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 6 Jun 2019 14:20:32 +0000 (10:20 -0400)
The bt2.CreationError exception type is reserved for cases where the
creation functions return None/NULL, which is usually because of
exhausted memory.  Other exception types should be used for other
errors.

This patch fixes a few instances where bt2.CreationError is wrongly
used.  Change them for ValueError, since they are cases of wrong
parameter value passed by the user.  We have already used ValueError for
cases like these, for example in
_UserMessageIterator._create_packet_beginning_message.

Change-Id: Ib66943f8dc1200f7b589764c171bf4764741a6bd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1383
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
bindings/python/bt2/bt2/stream_class.py
bindings/python/bt2/bt2/trace.py
bindings/python/bt2/bt2/trace_class.py
tests/bindings/python/bt2/test_stream_class.py
tests/bindings/python/bt2/test_trace_class.py

index f2869cb98cd50f11fbfe0063ea6f242d78ae3390..fa13cb3b83c9b715fc5dc401068a4dac9c984838 100644 (file)
@@ -61,12 +61,12 @@ class StreamClass(object._SharedObject, collections.abc.Mapping):
                            payload_field_class=None):
         if self.assigns_automatic_event_class_id:
             if id is not None:
-                raise bt2.CreationError('id provided, but stream class assigns automatic event class ids')
+                raise ValueError('id provided, but stream class assigns automatic event class ids')
 
             ec_ptr = native_bt.event_class_create(self._ptr)
         else:
             if id is None:
-                raise bt2.CreationError('id not provided, but stream class does not assign automatic event class ids')
+                raise ValueError('id not provided, but stream class does not assign automatic event class ids')
 
             utils._check_uint64(id)
             ec_ptr = native_bt.event_class_create_with_id(self._ptr, id)
index aa2757c0c170bc3fca77a07b616efaaf9088262c..ba7b89d8c57717696601705c7a350c25f8a243c1 100644 (file)
@@ -79,12 +79,12 @@ class Trace(object._SharedObject, collections.abc.Mapping):
 
         if stream_class.assigns_automatic_stream_id:
             if id is not None:
-                raise bt2.CreationError("id provided, but stream class assigns automatic stream ids")
+                raise ValueError("id provided, but stream class assigns automatic stream ids")
 
             stream_ptr = native_bt.stream_create(stream_class._ptr, self._ptr)
         else:
             if id is None:
-                raise bt2.CreationError("id not provided, but stream class does not assign automatic stream ids")
+                raise ValueError("id not provided, but stream class does not assign automatic stream ids")
 
             utils._check_uint64(id)
             stream_ptr = native_bt.stream_create_with_id(stream_class._ptr, self._ptr, id)
index 9ae57ade86e61c59b2487ce2bc712cc22ac2dc61..b8eeb30f22ef7a1d5059df15bf5e1787141ecad1 100644 (file)
@@ -176,12 +176,12 @@ class TraceClass(object._SharedObject, collections.abc.Mapping):
 
         if self.assigns_automatic_stream_class_id:
             if id is not None:
-                raise bt2.CreationError('id provided, but trace class assigns automatic stream class ids')
+                raise ValueError('id provided, but trace class assigns automatic stream class ids')
 
             sc_ptr = native_bt.stream_class_create(self._ptr)
         else:
             if id is None:
-                raise bt2.CreationError('id not provided, but trace class does not assign automatic stream class ids')
+                raise ValueError('id not provided, but trace class does not assign automatic stream class ids')
 
             utils._check_uint64(id)
             sc_ptr = native_bt.stream_class_create_with_id(self._ptr, id)
index 3eb695b1c5f8f00aa875eec89a642abc7b33c58c..243563f5bd7e16eda466f67f7f19136a32a04ddc 100644 (file)
@@ -70,7 +70,7 @@ class StreamClassTestCase(unittest.TestCase):
         sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
         self.assertTrue(sc.assigns_automatic_stream_id)
 
-        with self.assertRaises(bt2.CreationError):
+        with self.assertRaises(ValueError):
             self._trace.create_stream(sc, id=123)
 
     def test_no_automatic_stream_ids(self):
@@ -84,7 +84,7 @@ class StreamClassTestCase(unittest.TestCase):
         sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
         self.assertFalse(sc.assigns_automatic_stream_id)
 
-        with self.assertRaises(bt2.CreationError):
+        with self.assertRaises(ValueError):
             self._trace.create_stream(sc)
 
     def test_automatic_event_class_ids(self):
@@ -98,7 +98,7 @@ class StreamClassTestCase(unittest.TestCase):
         sc = self._tc.create_stream_class(assigns_automatic_event_class_id=True)
         self.assertTrue(sc.assigns_automatic_event_class_id)
 
-        with self.assertRaises(bt2.CreationError):
+        with self.assertRaises(ValueError):
             sc.create_event_class(id=123)
 
     def test_no_automatic_event_class_ids(self):
@@ -112,7 +112,7 @@ class StreamClassTestCase(unittest.TestCase):
         sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
         self.assertFalse(sc.assigns_automatic_event_class_id)
 
-        with self.assertRaises(bt2.CreationError):
+        with self.assertRaises(ValueError):
             sc.create_event_class()
 
     def test_packets_have_default_beginning_clock_snapshot(self):
index 265b0de8b40ed8ac0604216688235a870a7a8a95..4f19b4a2bc8c173d9986ab68119a93600fe232b8 100644 (file)
@@ -45,7 +45,7 @@ class TraceClassTestCase(unittest.TestCase):
         tc = run_in_component_init(f)
         self.assertTrue(tc.assigns_automatic_stream_class_id)
 
-        with self.assertRaises(bt2.CreationError):
+        with self.assertRaises(ValueError):
             sc1 = tc.create_stream_class(23)
 
     def test_no_assigns_automatic_stream_class_id(self):
@@ -66,7 +66,7 @@ class TraceClassTestCase(unittest.TestCase):
         self.assertFalse(tc.assigns_automatic_stream_class_id)
 
         # In this mode, it is required to pass an explicit id.
-        with self.assertRaises(bt2.CreationError):
+        with self.assertRaises(ValueError):
             tc.create_stream_class()
 
     def test_env_get(self):
This page took 0.028908 seconds and 4 git commands to generate.