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>
payload_field_class=None):
if self.assigns_automatic_event_class_id:
if id is not None:
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:
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)
utils._check_uint64(id)
ec_ptr = native_bt.event_class_create_with_id(self._ptr, id)
if stream_class.assigns_automatic_stream_id:
if id is not None:
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:
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)
utils._check_uint64(id)
stream_ptr = native_bt.stream_create_with_id(stream_class._ptr, self._ptr, id)
if self.assigns_automatic_stream_class_id:
if id is not None:
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:
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)
utils._check_uint64(id)
sc_ptr = native_bt.stream_class_create_with_id(self._ptr, id)
sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
self.assertTrue(sc.assigns_automatic_stream_id)
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):
self._trace.create_stream(sc, id=123)
def test_no_automatic_stream_ids(self):
sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
self.assertFalse(sc.assigns_automatic_stream_id)
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):
self._trace.create_stream(sc)
def test_automatic_event_class_ids(self):
sc = self._tc.create_stream_class(assigns_automatic_event_class_id=True)
self.assertTrue(sc.assigns_automatic_event_class_id)
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):
sc.create_event_class(id=123)
def test_no_automatic_event_class_ids(self):
sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
self.assertFalse(sc.assigns_automatic_event_class_id)
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):
sc.create_event_class()
def test_packets_have_default_beginning_clock_snapshot(self):
tc = run_in_component_init(f)
self.assertTrue(tc.assigns_automatic_stream_class_id)
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):
sc1 = tc.create_stream_class(23)
def test_no_assigns_automatic_stream_class_id(self):
self.assertFalse(tc.assigns_automatic_stream_class_id)
# In this mode, it is required to pass an explicit id.
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):
tc.create_stream_class()
def test_env_get(self):