From: Philippe Proulx Date: Sat, 11 Feb 2017 18:23:12 +0000 (-0500) Subject: bt2: raise when bt2.create_plugin_from_name() finds nothing X-Git-Tag: v2.0.0-pre1~484 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=9a0a47aeda7c5de37b7090c074bd9031109bb47d;hp=5933c0f2e81353a0bce0893f44408be7014ca500;p=babeltrace.git bt2: raise when bt2.create_plugin_from_name() finds nothing 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 Signed-off-by: Jérémie Galarneau --- diff --git a/bindings/python/bt2/__init__.py.in b/bindings/python/bt2/__init__.py.in index 452cb326..ba196289 100644 --- a/bindings/python/bt2/__init__.py.in +++ b/bindings/python/bt2/__init__.py.in @@ -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 diff --git a/bindings/python/bt2/plugin.py b/bindings/python/bt2/plugin.py index 9ce4c53a..920eb636 100644 --- a/bindings/python/bt2/plugin.py +++ b/bindings/python/bt2/plugin.py @@ -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)