bt2: raise when bt2.create_plugin_from_name() finds nothing
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 11 Feb 2017 18:23:12 +0000 (13:23 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
Returning None from this function when there's no plugin is Pythonically
weird:

    plugin = bt2.create_plugin_from_name()
    print(plugin.name)

The execution should not reach print() here when the plugin is not
found.

Raise the new bt2.NoSuchPluginError exception instead.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/bt2/__init__.py.in
bindings/python/bt2/plugin.py

index 452cb3267c3c5518b915ef281db0d68c97bfea1d..ba196289f28258dce0ccd23c320bbb48d8bdbb1d 100644 (file)
@@ -50,6 +50,10 @@ class FrozenError(Error):
     pass
 
 
+class NoSuchPluginError(Error):
+    pass
+
+
 class UnsupportedFeature(Exception):
     pass
 
@@ -66,7 +70,6 @@ class IncompleteUserClassError(Error):
     pass
 
 
-
 import bt2.native_bt as _native_bt
 import atexit
 
index 9ce4c53a61ab3f228209e2df40ba03324af388d9..920eb63642d71502868c3cc3becbe69e3c41e3af 100644 (file)
@@ -61,7 +61,7 @@ def create_plugin_from_name(name):
     plugin_ptr = native_bt.plugin_create_from_name(name)
 
     if plugin_ptr is None:
-        return
+        raise bt2.NoSuchPluginError(name)
 
     return _Plugin._create_from_ptr(plugin_ptr)
 
This page took 0.024865 seconds and 4 git commands to generate.